Coinitialize (nil) and CoInitializeEx (0, COINIT_MULTITHREADED)

in the stream, is there any difference if I use

Coinitialize(nil) 

instead

 CoInitializeEx(0, COINIT_MULTITHREADED); 

I am using Delphi 7, but I assume that the question may remain for other programming languages. Thank you for your help.

+6
source share
1 answer

The first initializes COM so that it places the calling thread in its single-threaded apartment (STA). The latter initializes COM in such a way that it places the calling thread into a shared multi-threaded apartment (MTA). These two apartments have very different semantics, especially in how COM objects are accessed through the boundaries of the flows. Themes in different apartments should use proxies to share COM objects, but COM provides synchronization for you (via message queues in streams). Threads in the same apartment can share COM objects without using a proxy, but must be synchronized manually, for example, with critical sections or mutexes.

So there is a difference, and that can be very important. Please read the documentation on MSDN, this is very detailed.

CoInitialize Function

CoInitializeEx Function

Processes, Threads, and Apartments

+11
source

Source: https://habr.com/ru/post/957750/


All Articles