Receiving COM events

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


    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.

    链接地址: http://www.djcxy.com/p/81302.html

    上一篇: 如何在接收器对象上实现传出接口(C ++)

    下一篇: 接收COM事件