作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试在现有 COM 组件中构建连接点。我从 CCmdTarget 派生类,并按照 MSDN 中的描述在类声明和实现中调用 MFC 宏。组件已正确构建、链接和运行。但是,当我调试我的客户端应用程序时,我看到以下问题:
客户端找到了正确的组件,找到了连接点容器,但在 FindConnectionPoint 上失败并返回 E_NOINTERFACE。我怀疑我必须添加或修改一些 MFC 宏才能将我的连接点包含到容器中,但不确定如何执行此操作。
所以,请帮我解决这个问题,或者给我一个提示,告诉我在哪里可以找到这个问题。
提前致谢, 豪沃
[ 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
// ..
最佳答案
CONNECTION_PART(SMCLink, IID_IConnectionPointContainer, AdHocPresenceEvents)
第二个参数应该是an IID of connection pointer interface .
关于c++ - FindConnectionPoint 返回 E_NOINTERFACE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8430773/
我正在尝试订阅 MBN 事件。这是我的代码: void subscribeToMbnEvents() { dwError = CoInitializeEx(NULL, COINIT_MULTI
我正在尝试在现有 COM 组件中构建连接点。我从 CCmdTarget 派生类,并按照 MSDN 中的描述在类声明和实现中调用 MFC 宏。组件已正确构建、链接和运行。但是,当我调试我的客户端应用程序
我是一名优秀的程序员,十分优秀!