views:

441

answers:

2

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

+1  A: 

c++ doesn't have built in thread support. What you are looking for depends on how you are implementing threads in your application. Win32? pthreads? boost::threads? Whichever API you are using will determine the answer to your question.

EDIT: looks like this may have an example for you: http://msdn.microsoft.com/en-us/library/system.threading.apartmentstate.aspx

It looks like it applies to managed c++.

Evan Teran
+4  A: 

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 calls CoInitializeEx (or CoInitialize), 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 the COINIT_MULTITHREADED flag to CoInitializeEx. To indicate that the thread should host an STA, either call CoInitialize or pass the COINIT_APARTMENTTHREADED flag to CoInitializeEx.
...

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

Shog9