
Enable COM clients call methods inside COM events
I suspect the problem is not on the COM side, but on the driver
side. Your callback has not returned yet (waiting for the client to
process the event on the other thread) when you call the Play
method. This may be causing the crash. The solution is not to fire
the event from within the driver callback. Post yourself a message
and raise the event from the message handler. This also makes
the whole sink marshaling ringmarole unnecessary (since your
hidden window will reside on your object's STA thread anyway).
You create the hidden window in FinalConstruct (also see the
CContainedWindow class and ALT_MSG_MAP) and DestroyWindow
it in FinalRelease.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
Quote:
> Hi,
> I've implemented an ATL ActiveX control for handling telephony methods and
> events asynchronously.
> One of the control's methods (OpenChannel) creates a worker thread to poll
> for telephony events passing the 'this' pointer as the thread's function
> parameter. Instead of marshaling the interface pointer before I create the
> thread, I just implemented my connection points from IConnectionPointImplMT
> (it's a class provided by Microsoft to enable firing events from worker
> thread, as shown in this article:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;Q280512).
> Another method enables the client to play a simple message file (Play) and
> returns immediately. When the worker thread gets a notification from the
> telephony card driver that the message has finished playing, it fires an
> event (OnPlayFinished) to notify the client about that. It works very fine.
> My problem now is, if I call the Play method just inside the OnPlayFinished
> event, an access violation occurs (it has been noted in VB clients).
> So, I ask: can I call COM methods inside a COM event when this event is
> fired from other thread than the main thread ? How can I accomplish this ?
> Thanks in advance for any help,
> --
> []'s
> Raul M. Fragoso