龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

COM中的可连接对象与连接点机制及其MFC程序实现(6)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
STDMETHODIMP CConnClientDlg::XEventSink::QueryInterface(REFIID riid,void** ppvObj) { METHOD_PROLOGUE(CConnClientDlg,EventSink) if(IsEqualIID(riid,IID_IUnknown)|| IsEqualIID(riid,IID_IEventSink)) { *pp

STDMETHODIMP

CConnClientDlg::XEventSink::QueryInterface(REFIID riid,void** ppvObj)

{

METHOD_PROLOGUE(CConnClientDlg,EventSink)

if(IsEqualIID(riid,IID_IUnknown)||

IsEqualIID(riid,IID_IEventSink))

{

*ppvObj = this;

AddRef();

return S_OK;

}

else

{

return E_NOINTERFACE;

}

}

STDMETHODIMP

CConnClientDlg::XEventSink::EventHandle() //此函数将被可连接对象调用

{

::AfxMessageBox("源对象向事件接收器发出了的通知!");

return S_OK;

  4.初始化COM库并创建组件对象实例

  在CConnClientDlg::OninitDialog()中写入:

HRESULT hResult;

hResult = ::CoInitialize(NULL);

if(FAILED(hResult))

{

::AfxMessageBox("不能初始化COM库!");

return FALSE;

}

m_pIUnknown = NULL;

hResult = ::CoCreateInstance(CLSID_ConnObject,NULL,

CLSCTX_INPROC_SERVER,IID_IUnknown,(void**)&m_pIUnknown);

if(FAILED(hResult))

{

m_pIUnknown = NULL;

::AfxMessageBox("不能创建ConnObject对象!");

return FALSE;

}

m_dwCookie = 0;//预置连接标识为0

精彩图集

赞助商链接