views:

269

answers:

1

Without:

  • ATL
  • MFC

Note:

  • Plain C++
  • Out-of-process COM Object/server
  • Predefined TLB file

Question:

  • How to implement an outgoing interface, so the COM Object can notify the sink of events?
  • How to handle the event appropriately, once received?

Below is the event function I'd like to implement - from TLB file:

inline HRESULT IS8SimulationEvents::S8SimulationEndRun ( ) {
    HRESULT _result = 0;
    _com_dispatch_method(this, 0x2, DISPATCH_METHOD, VT_ERROR, (void*)&_result, NULL);
    return _result;
}

Regards

+2  A: 

Implement the source interface in COM Server class. You should implement IConnectionPointcontainer if you are not using the ATL.

In the client class call the COM server as mentioned below. 1. Call FindConnectionPointContainer 2. Call FindConnectionPoint 3. Call Advise on the interface pointer returned from step 2, we should provide IUnknown pointer of sink object. Advise returns a cookie, that we can use it while calling the unadvise.

To handle the events you can do it 2 ways one using the IDispatch's Invoke method to resolve the calls in Client side other is server itself calls the particular Sink method. Both the method uses the IUnknown pointer that it gets while advising.

Vinay
How can I confirm that the COM object has a source interface already? I'm working with a predefined TLB file.
Aaron
Found "dispinterface IS8SimulationEvents" - helpstring("Events interface for S8Simulation Object"). Is this it?
Aaron
Usually interfaces with "Events" are sink interfaces meaning "Should be implemented by client" and the interface which is above this interface is source interface
Vinay
OK, so i'll attempt to implement IS8SimulationEvents - sink interface - from Client side. Sorry please excuse me I still don't understand: interface IS8Simulation - is above (in OLEVIEW)
Aaron
OleView is a Microsoft's application to view all the COM components, their interfaces registered in your computer. If your COM server is registered then it should be listed in OleView.
Vinay
Using OLEVIEW, I found IConnectionPointContainer as one of the interfaces provided by the COM object. Does this mean I dont need to implement this?
Aaron
Do you have an example, how to use the IDispatch invoke method
Aaron
Not able to get the example in pure C++.This may helpshttp://www.codeguru.com/cpp/g-m/multimedia/graphics/article.php/c12229
Vinay
Just what I was looking for thanks :)
Aaron