COleDispatchDriver::AttachDispatch
呼叫 AttachDispatch 成員函式附加 IDispatch 指標 COleDispatchDriver 物件。 如需詳細資訊,請參閱 Implementing the IDispatch Interface。
void AttachDispatch(
LPDISPATCH lpDispatch,
BOOL bAutoRelease = TRUE
);
參數
lpDispatch
要附加的 OLE IDispatch 物件的指標 COleDispatchDriver 物件。bAutoRelease
指定是否要釋放這個分派,這個物件超出範圍。
備註
這個函式會釋放已附加至 COleDispatchDriver 物件的所有 IDispatch 指標。
範例
void COleContainerView::OnAttachDispatch()
{
CLSID clsidWMP;
LPDISPATCH pWMPDispatch = NULL;
COleDispatchDriver oddWMP;
try
{
AfxCheckError(::CLSIDFromProgID(_T("WMPlayer.OCX"), &clsidWMP));
AfxCheckError(::CoCreateInstance(clsidWMP, NULL, CLSCTX_INPROC_SERVER,
IID_IDispatch, (LPVOID*)&pWMPDispatch));
oddWMP.AttachDispatch(pWMPDispatch, TRUE);
pWMPDispatch = NULL; // our COleDispatchDriver now owns the interface
CString strUIMode;
oddWMP.GetProperty(23, VT_BSTR, (void*)&strUIMode);
TRACE(_T("WMP uiMode is %s.\n"), strUIMode);
}
catch (COleException* pe)
{
pe->ReportError();
pe->Delete();
}
catch (CMemoryException* pe)
{
pe->ReportError();
pe->Delete();
}
// cleanup
if (NULL != pWMPDispatch)
{
pWMPDispatch->Release();
}
// COleDispatchDriver automatically releases the dispatch interface when
// it goes out of scope if m_bAutoRelease is TRUE.
}
需求
Header: afxdisp.h
請參閱
參考
COleDispatchDriver::DetachDispatch
COleDispatchDriver::ReleaseDispatch
COleDispatchDriver::CreateDispatch