1

I've got a set of tasks that I slaved to the NT threadpool using QueueUserWorkItem. I need to make some calls to COM from these separate threads to access data inside WMI. I'm unsure, however, how the correct calls to CoInitializeEx need to be made.

Basically, the CoInitializeEx docs say that the call should be made once per thread. But I don't own these threads—NT does. I don't know when they get created or destroyed, or anything of that nature. Do I basically call ::CoInitializeEx() (with COINIT_MULTITHREADED) at the beginning of the thread routine, and then ::CoUninitialize() at the end of my thread routine?

4

1 回答 1

1

您可以调用多个嵌套时间CoInitCoUninit它们只需要平衡即可。您提出的在线程过程的开头和结尾执行此操作的解决方案是合理的。只要确保您没有任何跳过调用的提前退出,并且如果失败CoUninit也不要调用。CoUninitCoInit

于 2011-10-18T17:20:01.230 回答