Reputation: 73433
In C# there is a method SetApartmentState
in the class Thread
.
How do I do the same thing in C++?
Upvotes: 6
Views: 2420
Reputation: 159688
For unmanaged processes, you control the apartment model used for a thread by passing appropriate parameters to CoInitializeEx()
. Larry Osterman wrote up a great little guide to these:
...
When a thread callsCoInitializeEx
(orCoInitialize
), the thread tells COM which of the two apartment types it’s prepared to host. To indicate that the thread should live in the MTA, you pass theCOINIT_MULTITHREADED
flag toCoInitializeEx
. To indicate that the thread should host an STA, either callCoInitialize
or pass theCOINIT_APARTMENTTHREADED
flag toCoInitializeEx
.
...
Upvotes: 10