Enable COM clients call methods inside COM events 
Author Message
 Enable COM clients call methods inside COM events

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://www.*-*-*.com/ ;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



Thu, 09 Dec 2004 04:40:55 GMT  
 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



Sat, 11 Dec 2004 02:29:56 GMT  
 Enable COM clients call methods inside COM events
Hi Alexander,

You was right, the problem was calling a driver function while the callback
is busy. The message pump solution you suggested is working nice now.
Thank you very much for your help.

--
[]'s

Raul M. Fragoso


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.



Sat, 11 Dec 2004 15:01:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. COM client crashes calling COM method

2. Please Help - How to get the Client ID inside a COM server function call

3. Calling COM method from managed c++ client

4. Problem calling VB COM dll from VC++ multithreaded COM EXE client

5. Calling a COM call back object's method fails if it is in Windows 98

6. COM Architecture and Inside COM

7. Create instance of an com object inside a the Com server

8. Problem with scripting context when using VB com object inside VC com object

9. problems passing ADO Recordset from VB-COM client to VC-COM-Server dll

10. COM/ATL novice:passing object pointers through methods on a COM interface

11. Call Com objects inside c++ object

12. Return a pointer to a nested COM object from a COM object method

 

 
Powered by phpBB® Forum Software