不好意思刚才没写清楚,我需要的是 VC++.NET 的代码。
先谢谢各位了。

解决方案 »

  1.   

    问题太大,看看com有关连接点(connection point)的文章吧,但我个人觉得如果做服务端程序不要用,估计这些都是TCE(tightly coupled events)的,也就是阻塞的
      

  2.   

    问题不大啊,人家厂商都把 com 做好了,并且给出了接口,我就是不会使用它给的接口啊,一般的接口我会用,就是事件接口,我不知道怎么用。
    拜托啦
      

  3.   

    这个只是 com 的普通操作啊,不至于这么难吧???
    第一个给出能调试通过的 vc++.net 代码的,马上就结贴给分!!!
      

  4.   

    要什么代码呢, ATL的中这个很简单的呀!!!!!
    具体的我也不记得了
      

  5.   

    推荐你看看<<ATL开发指南>>, .NET不是万能药, 隐藏复杂性固然好, 不过最终还是需要学习COM的基本技术.
      

  6.   

    楼上的,我没有要托管 vc.net 代码,就是常规的,没有用到 .net 的内容,编程感觉几乎和 vc6 一样,只是 ide 方便了。
    这个问题不就是 com 的基础吗???感觉应该很简单啊!没人知道吗?
      

  7.   

    // evh_client.cpp
    // compile with: /link /OPT:NOREF
    #define _ATL_ATTRIBUTES 1
    #include <atlbase.h>
    #include <atlcom.h>
    #include <stdio.h>
    #include "evh_server.h" //此处为com头文件[ module(name="EventReceiver") ];[ event_receiver(com) ]
    class CReceiver { //接受器com
    public:
       HRESULT MyHandler1(int nValue) { //处理函数
          printf("MyHandler1 was called with value %d.\n", nValue);
          return S_OK;
       }   HRESULT MyHandler2(int nValue) {
          printf("MyHandler2 was called with value %d.\n", nValue);
          return S_OK;
       }   void HookEvent(IEventSource* pSource) { //连接事件
          __hook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler1);
          __hook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler2);
       }   void UnhookEvent(IEventSource* pSource) { //取消连接
          __unhook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler1);
          __unhook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler2);
       }
    };int main() { //.exe
       // Create COM object
       CoInitialize(NULL);
       IEventSource* pSource = 0;
       HRESULT hr = CoCreateInstance(__uuidof(CSource), NULL, CLSCTX_ALL, 
          __uuidof(IEventSource), (void **) &pSource);
       if (FAILED(hr)) {
          return -1;
       }   // Create receiver and fire event
       CReceiver receiver;
       receiver.HookEvent(pSource);
       pSource->FireEvent();
       receiver.UnhookEvent(pSource);   CoUninitialize();
       return 0;
    }
    //注:CSource是服务器Com类
    //代码使用了vs.net的属性编程,没有使用托管代码
    //其实是vs.net的例子:)