接收COM事件 [英] Receiving COM events

查看:126
本文介绍了接收COM事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有:




  • ATL

  • MFC



    • 注意:




      • 普通 C ++
      • 进程外 COM对象/服务器

      • 预定义的TLB文件



      问题:




      • 如何实现 ,因此COM对象可以通知 sink 的事件?

      • 如何正确处理事件,一旦收到?



      下面是我要实现的事件函数 - 从 TLB 文件:

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


      $ b $ p


      解决方案

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



      在客户端类中调用COM服务器,如下所述。
      1.调用FindConnectionPointContainer
      2.调用FindConnectionPoint
      3.对从步骤2返回的接口指针调用Advise,我们应该提供sink对象的IUnknown指针。 Advise会返回一个cookie,我们可以在调用unadvise时使用它。



      要处理事件,您可以使用IDispatch的Invoke方法解析客户端的调用
      other是服务器本身调用特定的Sink方法。这两个方法都使用IUnknown指针,它在获得建议。


      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.

      这篇关于接收COM事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆