What is equivalent to Thread.SetApartmentState in C ++?

In C #, there is a method SetApartmentStatein the class Thread. How do I do the same in C ++?

+5
source share
2 answers

For unmanaged processes, you control the model of the apartment used for the flow, passing the appropriate parameters CoInitializeEx(). Larry Osterman wrote a great reference:

...
When the stream calls CoInitializeEx(or CoInitialize), the stream tells COM which of the two types of apartments is prepared for acceptance. To indicate that the stream should live in the MTA, you pass a flag COINIT_MULTITHREADED CoInitializeEx. To indicate that the stream should have an STA, either call CoInitializeor pass a COINIT_APARTMENTTHREADEDflag CoInitializeEx.
...

- http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx

+7
source

C ++ does not have native thread support. What you are looking for depends on how you implement threads in your application. Win32 Pthreads? promotion :: topics? Whatever API you use, the answer to your question will be determined.

EDIT: , : http://msdn.microsoft.com/en-us/library/system.threading.apartmentstate.aspx

, ++.

+1

All Articles