Coinitialize(nil) and CoInitializeEx(0, COINIT_MULTITHREADED) difference

夙愿已清 提交于 2019-12-05 02:05:59
David Heffernan

The former initializes COM in a way that puts the calling thread into its own single-threaded apartment (STA). The latter initializes COM in a way that puts the calling thread into a shared multi-threaded apartment (MTA). The two apartments have very different semantics, especially in how COM objects are accessed across thread boundaries. Threads in different apartments must use proxies to share COM objects, but COM provides synchronization for you (via per-thread messages queues). Threads in the same apartment can share COM objects without using proxies, but must synchronize manually, such as with critical sections or mutexes.

So yes, there is a difference and it can be very significant. Please read the documentation on MSDN, it is very detailed.

CoInitialize function

CoInitializeEx function

Processes, Threads, and Apartments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!