使用smart pointer:如对象为yourcom.MyCom#import "x:\xxx\yourcom.dll" no_namespaceIMyComPtr pMyCom(__uuidof(MyCom));pMyCom->MyMethod();

解决方案 »

  1.   

    使用smart pointer:如对象为yourcom.MyCom#import "x:\xxx\yourcom.dll" no_namespaceIMyComPtr pMyCom(__uuidof(MyCom));pMyCom->MyMethod();....
    pMyCom->Release();
      

  2.   

    使用IUnknown指针,以下是两个有用的函数
    HRESULT GetUnknown(WCHAR * strProgID, IUnknown ** ppunknown)
    {
    /**********************************************************************/
    CLSID clsid;
    HRESULT hresult = ::CLSIDFromProgID(strProgID, &clsid);
    hresult = ::CoCreateInstance(clsid,NULL,CLSCTX_SERVER,
    IID_IUnknown,(void **)ppunknown);
    /***********************************************************************/
    return S_OK;
    };HRESULT GetInterface(IUnknown * punknown, REFIID riid, IUnknown ** ppunknown)
    {
    HRESULT hresult = punknown->QueryInterface(riid,(void **)ppunknown);
    return S_OK;
    };
    比如你的COM接口为IMyClient4
    #include "你的COM的头文件"
    #include "你的COM的.c文件"
    IUnknown *punknown;
    IMyClient4 *pMyClient;
    GetUnknown(L"EventClient4.MyClient4",&punknown);
    GetInterface(punknown,IID_IMyClient4,(IUnknown **)&pMyClient);
      

  3.   

    OH MY god .what are you doing ?what you mean is com pooling or creating a com
    object?
      

  4.   

    and located or remoted ?
      

  5.   

    com已经死了,看看.net吧。
    ATL现在变化挺大,不过很多东西是为了写服务器,跟com无关。
    微软说com用于和传统的com代码通信,将来用基于.net的组件.
    com+已经是.net的一部分,使用起来简单多了。忘了addref和IDL吧!
      

  6.   

    如何在vc中调用远程vb编写的dll组件?