#import "c:\\test\\test.dll"//假定你的com是在test.dll中实现的

解决方案 »

  1.   

    如果我定义了两个接口,比方说IInterface1,IInterface2,
    在它们的类中CInterface1要引用接口IInterface2,可能用下面的方式:
    IInterface2Ptr pInt;
    我的两个类都在同一个DLL中,我怎么IMPORT自已?
      

  2.   

    Q181265: HOWTO: Create ATL COM Objects (http://support.microsoft.com/support/kb/articles/Q181/2/65.asp) To create a COM object in ATL locally, do the following (search on article ID number Q181265 for the Microsoft Knowledge Base article "HOWTO: Create COM ATL Objects" for more information)://CGoo is class implementing IGoo
    CComObject<CGoo>* pGoo;
    // Note that at this point the ref count for the object is 0.
    HRESULT hRes = CComObject< CGoo >::CreateInstance(&pGoo);//smart pointer for IGoo
    IGooPtr spGoo;
    pGoo->QueryInterface(IID_IGoo, (void**) &spGoo);
    // use spGoo now, refcount is 1...We're using the ATL object template class here, and calling the ATL static method CreateInstance to create the object. This is the function that would otherwise be called by the class factory—so this is the right way to create objects without using a class factory.After we create the object, we call QueryInterface using the ATL smart pointer but pass the COM smart pointer. At this point, we use the object through spGoo so we can take advantage of the helper functions to access properties.