FindConnectionPoint返回E_NOINTERFACE

时间:2011-12-08 12:05:18

标签: c++ com mfc connection point

我正在尝试在现有COM组件中构建连接点。 我从CCmdTarget派生类,并在类声明和实现中调用MFC宏,如MSDN中所述。组件正确构建,链接和运行。 但是,当我调试我的客户端应用程序时,我看到以下问题:

客户端找到正确的组件,找到连接点容器,但在带有E_NOINTERFACE的FindConnectionPoint上失败。 我怀疑我必须添加或修改一些MFC宏以将我的连接点包含到容器中,但不知道如何执行此操作。

所以,请帮我解决这个问题,或者提示在哪里寻找问题。

提前致谢,   Hovo


[ uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), version(1.0) ]
library SMC
{
    importlib("stdole32.tlb");
    importlib("stdole2.tlb");
    [
        uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),
        helpstring("_IAdHocPresenceEvents Interface")
    ]
    interface _IAdHocPresenceEvents : IUnknown
    {
        [id(1), helpstring("method OnAdHocPresenceQuery")] HRESULT OnAdHocPresenceQuery();
    };

    #include "ISMCLink.idl"

    [ uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) ]
    coclass SMCLink
    {
        dispinterface IDispSMCLink;
        [default] interface ISMCLink;
        interface ISMCLink2;
        [default, source] interface _IAdHocPresenceEvents;
    };
};

[ 
    helpstring("Interface to control My Product"),
    uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),
    dual,
    oleautomation
]
interface ISMCLink : IDispatch
{
    //...
    /** 
    * RequestAdHocPresence
    * 
    * Sends Ad Hoc Presence Query
    *
    * @param SIP address.
    *
    * @return S_OK if the In session window was opened successfully
    */
    [id(0x00000001), helpstring("method Request for Ad Hoc Presence")]
    HRESULT RequestAdHocPresence([in] BSTR user);
};

//  Primary dispatch interface for SMC
[ uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) ]
dispinterface IDispSMCLink
{
    interface ISMCLink;
};

// Definition for the new interface ISMCLink2
// ------------------------------------------

[
    helpstring("ISMCLink2, Interface to access My Product"),
    uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),
    dual,
    oleautomation
]
interface ISMCLink2 : ISMCLink
{
   //...
};

namespace MYPROD {

class SMCLink : public CCmdTarget
{
    //...

protected:

    DECLARE_MESSAGE_MAP()
    DECLARE_DISPATCH_MAP()
    DECLARE_INTERFACE_MAP()

    // Connection point for ISMCLink interface
    BEGIN_CONNECTION_PART(SMCLink, AdHocPresenceEvents)
        CONNECTION_IID(IID__IAdHocPresenceEvents)
    END_CONNECTION_PART(AdHocPresenceEvents)

    DECLARE_CONNECTION_MAP()


public:
    SMCLink(void);
    virtual ~SMCLink(void);

    // to be OLE creatable, it must be DYNCREATE and OLECREATE
    DECLARE_DYNCREATE(SMCLink)
DECLARE_OLECREATE(SMCLink)

    //..
    /** 
    * RequestAdHocPresence
    * 
    * Sends Ad Hoc Presence Query
    *
    * @param SIP address.
    *
    * @return S_OK if the In session window was opened successfully
    */
    afx_msg HRESULT RequestAdHocPresence(BSTR sipAddr);


    BEGIN_DUAL_INTERFACE_PART(DualSMCLink, ISMCLink)
        //...
    STDMETHOD(RequestAdHocPresence)(THIS_ BSTR user);
    END_DUAL_INTERFACE_PART(DualSMCLink)

};

} // namespace MYPROD

namespace MYPROD {

BEGIN_MESSAGE_MAP(SMCLink, CCmdTarget)
    //{{AFX_MSG_MAP(CAutoProxy)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

IMPLEMENT_DYNCREATE(SMCLink, CCmdTarget)


BEGIN_DISPATCH_MAP(SMCLink, CCmdTarget)
    //{{AFX_DISPATCH_MAP(SMCLink)
    //..
    DISP_FUNCTION(SMCLink, "RequestAdHocPresence", RequestAdHocPresence, VT_ERROR,     VTS_BSTR)
    //}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()


BEGIN_INTERFACE_MAP(SMCLink, CCmdTarget)
    INTERFACE_PART(SMCLink, IID_ISMCLink, DualSMCLink)
    INTERFACE_PART(SMCLink, IID_ISMCLink2, DualSMCLink)
    INTERFACE_PART(SMCLink, IID_IConnectionPointContainer, ConnPtContainer)
END_INTERFACE_MAP()

BEGIN_CONNECTION_MAP(SMCLink, CCmdTarget)
    CONNECTION_PART(SMCLink, IID_IConnectionPointContainer, AdHocPresenceEvents)
END_CONNECTION_MAP()


SMCLink::SMCLink(void)
{
    EnableAutomation();
    EnableConnections();
}

SMCLink::~SMCLink(void)
{
    //..
    if (registerCookie_ != 0)
        RevokeActiveObject(registerCookie_, NULL);
}


void SMCLink::registerActive()
{
    HRESULT hRes;
    hRes = RegisterActiveObject(GetInterface(&IID_IUnknown),
                                SMCLink::guid, NULL, &registerCookie_);
    //..
}

//..

afx_msg HRESULT SMCLink::RequestAdHocPresence(BSTR sipAddr)
{
    Sleep(1000);

    ::MessageBox(NULL, L"RequestAdHocPresence", L"RequestAdHocPresence", 0);

    Fire_AdHocPresenceStatus(); // HOWTO ???

    return S_OK;
}

STDMETHODIMP SMCLink::XDualSMCLink::RequestAdHocPresence(BSTR user)
{
    METHOD_PROLOGUE(SMCLink, DualSMCLink)

    return pThis->RequestAdHocPresence(user);
}

} // namespace MYPROD

    CLSID clientCLSID;
    if (FAILED(CLSIDFromProgID(A2BSTR("SMC.SMCLink"), &clientCLSID)))
    {
        clientCLSID = SMC::CLSID_SMCLink;
    }

    LPUNKNOWN lpUnk;
    SMC::ISMCLink* m_pSMCLink = NULL;
    if (m_pSMCLink == NULL)
    {
        if (GetActiveObject(clientCLSID, NULL, &lpUnk) == NOERROR)
        {
            hr = lpUnk->QueryInterface(SMC::IID_ISMCLink, (LPVOID*)&m_pSMCLink);
            lpUnk->Release();
        }
    }

    hr = m_pSMCLink->RequestAdHocPresence(A2BSTR("someuser@mydomain"));
    // this returns S_OK


    IConnectionPointContainer   * pConnPtContainer = NULL;
    IConnectionPoint          * pCP2 = NULL;   //these are declared as a member

    //check if this interface supports connectable objects
    hr = m_pSMCLink->QueryInterface(IID_IConnectionPointContainer,(void     **)&pConnPtContainer);
     // this returns S_OK

    IEnumConnectionPoints* pEnum = NULL;
    hr = pConnPtContainer->EnumConnectionPoints( &pEnum );
    // this returns S_OK

    hr = pConnPtContainer->FindConnectionPoint(IID__IAdHocPresenceEvents, &pCP2);
    // this returns E_NOINTERFACE

    // ..

1 个答案:

答案 0 :(得分:2)

CONNECTION_PART(SMCLink, IID_IConnectionPointContainer, AdHocPresenceEvents)

第二个论点应该是an IID of connection pointer interface