Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rules for calling CoInitilizeEx

4 views
Skip to first unread message

Barzo

unread,
Oct 15, 2009, 12:30:32 PM10/15/09
to
Hi,

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.

Igor Tandetnik

unread,
Oct 15, 2009, 10:45:15 PM10/15/09
to
Barzo wrote:
> In my application I need to raise some events from a second thread.

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

Barzo

unread,
Oct 16, 2009, 2:51:23 AM10/16/09
to
On 16 Ott, 04:45, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> Barzo wrote:
> > In my application I need to raise some events from a second thread.
>
> http://vcfaq.mvps.org/com/1.htm

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.

Igor Tandetnik

unread,
Oct 16, 2009, 12:35:00 PM10/16/09
to

I suppose the best way to find out whether something is too expensive is to measure it.

0 new messages