连接点实现问题!高手请进!!!!
qyluo 2003-02-27 04:59:05 void Connect()
{
if(m_dwCookie!=0)
{
return;
}
if(m_pIUnknown!=NULL)
{
HRESULT hResult;
hResult = m_pIUnknown->QueryInterface(IID_IConnectionPointContainer,
(void**)&pConnPtCont);
if(FAILED(hResult))
{
::AfxMessageBox("不能获取对象的IConnectionPointContainer接口!");
return;
}
ASSERT(pConnPtCont != NULL);
hResult = pConnPtCont->FindConnectionPoint(IID_ICMSCallControlEvent,&pConnPt);
if(FAILED(hResult))
{
pConnPtCont->Release();
::AfxMessageBox("不能获取对象的IEventSink连接点接口!");
return;
}
ASSERT(pConnPt != NULL);
//获取事件接收器指针
IUnknown* pIEventSink;
m_xEventSink.QueryInterface(IID_IUnknown,(void**)&pIEventSink);
//通过连接点接口的Advise方法将事件接收器指针传给可连接对象
if(SUCCEEDED(pConnPt->Advise(pIEventSink,&m_dwCookie)))
{
::AfxMessageBox("与可连接对象ConnObject建立连接成功!");
}
else
{
::AfxMessageBox("不能与ConnObject建立连接!");
}
pConnPt->Release();
pConnPtCont->Release();
}
}
我的COM对象是用MFC实现的,以上是我的客户端连接部分的代码,函数pConnPt->Advise(pIEventSink,&m_dwCookie)之前的代码都运行正常,hr返回为0,但是就是
Advise()调用返回结果不正确,实在不明白为什么,不知道是我的客户端的代码的问题,还是服务器端的代码的问题,哪位大侠指点一下!!!!!