1

没有:

  • ATL
  • MFC

笔记:

  • C++
  • 进程外COM 对象/服务器
  • 预定义的 TLB 文件

问题:

  • 如何实现一个传出接口,以便 COM 对象可以通知接收事件?
  • 一旦收到,如何妥善处理事件?

下面是我想实现的事件函数 - 来自TLB文件:

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

问候

4

1 回答 1

2

在 COM Server 类中实现源接口。如果您不使用 ATL,则应该实现 IConnectionPointcontainer。

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.

于 2009-01-18T11:44:06.163 回答