Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting for COM messages

Status
Not open for further replies.

SebastianStricker

Programmer
Aug 28, 2003
10
0
0
DE
Hello guys,

I have a question about waiting for a COM message in a function:

I set up an event-sink for COM events from another application in my function. Then I want the function to stop until the sink signalises that a COM message is received. The problem is that when i call WaitForSingleObject or something to wait for a CEevent or another synchronisation object, the whole thread sleeps an my sink with him - so the incoming messages are not processed.

I then tried to create a second thread with a local sink variable but what to do in this thread? I only want that thread to create a sink instance and then wait for incoming messages.

Remark: my sink is derived from CCmdTarget, may be there is a way of "polling" for incoming messages...?

Thanks,
Sebastian
 
You should create a class derived from IAdviseSink.
Theer are three server objects what use your class, so you will call one of:
IOleObject::Advise/IOleObject::Unadvise
IDataObject::DAdvise/IDataObject::DUnadvise
IViewObject::SetAdvise/ IViewObject::SetAdvise(NULL
the functions return a cookie which you will pass go Unadvise methods

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
OK, I guess this would be a way but the problem is that it was relatively complicated to get the sink class work so I'm looking for a solution using my (working) sink instead of implementing a new one.

I noticed that when I create a new thread with a local sink derived from CCmdTarget, this thread blocks processor time and no other thread continues. Do you have any idea how I can change this? This would probably solve my problem.

Thanks Sebastian.
 
the way I specified above is a standard communication way in COM API. By the way, IAdviseSink is not complicated at all. When you got you COM server object instance, just query one of interfaces IOleObject,IDataObject,IViewObject by calling
yourObject->QueryInterface
and use as IID one of:
IID_IOleObject,IID_IDataObject,IID_IViewObject

yourObject is supposed to be a pointer to an IUnknown


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Ok. My actual sink uses a special IID out of an DLL from the server application (this DLL is included via "#import"). I use this IID for the INTERFACE_MAP and the AfxConnectionAdvise method. The event handler functions are declared in a DISPATCH_MAP. Would this be the same in an IAdviseSink-derived class?

Thanks for your help,
Sebastian.
 
I think(maybe is false) DISPATCH_MAP is an implementation of IDispatch. You could use IDispatch for events processing witn connection points, but this way is more complicated.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top