Я пытаюсь построить точки подключения в существующем компоненте COM.
Я извлекаю класс из CCmdTarget и вызываю макросы MFC в объявлении и реализации класса, как описано в MSDN. Компонент правильно построен, связан и запущен.
Однако, когда я отлаживаю свое клиентское приложение, я вижу следующую проблему:
Клиент находит правильный компонент, находит контейнер точки подключения, но завершается ошибкой в FindConnectionPoint с E_NOINTERFACE.
Я подозреваю, что мне нужно добавить или изменить некоторые макросы 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, ®isterCookie_);
//..
}
//..
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
// ..