In my application I need to raise some events from a second thread.
In detail I have a Sound library callback that send me audio data
(and, I think, lives in a thread different from the main one) and
inside this callback I have to raise an event to the clients.
Since I cannot modify the thread entry point function, can I do
something like this:
void MySoundCallback(..)
{
....
#if(WIN32 && _WIN32_DCOM)
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
#endif
//Raise the event
this->RaiseChangeStatusEvent(STATE_STOPPED, 0);
#if(WIN32 && _WIN32_DCOM)
CoUninitialize();
#endif
....
}
Is this a correct approach?
Thanks,
Daniele.
http://vcfaq.mvps.org/com/1.htm
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Yes, I had already read the faq, and in my projects I use the 3th
solution (with GIT).
In fact the method I posted works.
But I asked to know if this solution may appear like a trick and is
expensive to call CoInit/CoUninit each time or maybe is ok.
Thanks.
Daniele.
I suppose the best way to find out whether something is too expensive is to measure it.