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选件类

层次结构图

COleDispatchDriver::DetachDispatch

COleDispatchDriver::ReleaseDispatch

COleDispatchDriver::CreateDispatch

COleDispatchDriver::m_lpDispatch

COleDispatchDriver::m_bAutoRelease