Coinitialize(nil) and CoInitializeEx(0, COINIT_MULTITHREADED) difference
Asked Answered
Y

1

14

in a thread, is there a difference if I use

Coinitialize(nil)

instead of

CoInitializeEx(0, COINIT_MULTITHREADED);

I use Delphi 7 but I presume the question can remain for other programming languages Thanks for your help.

Yangyangtze answered 9/11, 2013 at 19:35 Comment(3)
Did you read the documentation on CoInitialize?Farver
yes I did but it is not clearYangyangtze
Perhaps you could elaborate on which part of the documentation you are struggling with.Dou
D
16

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

Dou answered 9/11, 2013 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.