다음을 통해 공유


COleDispatchDriver::CreateDispatch

생성은 IDispatch 인터페이스 개체를 연결 하 고는 COleDispatchDriver 개체.

BOOL CreateDispatch( 
   REFCLSID clsid, 
   COleException* pError = NULL  
); 
BOOL CreateDispatch( 
   LPCTSTR lpszProgID, 
   COleException* pError = NULL  
);

매개 변수

  • clsid
    클래스의 ID는 IDispatch 연결 개체를 만들 수 있습니다.

  • pError
    OLE 예외에서 생성 되는 상태 코드를 보유 하는 개체에 대 한 포인터입니다.

  • lpszProgID
    자동화 개체 디스패치 개체를 만들 수 있습니다 "Excel.Document.5" 등의 프로그래밍 방식 식별자에 대 한 포인터입니다.

반환 값

성공 시 0이 아닌. 그렇지 않으면 0입니다.

예제

void COleContainerView::OnCreateDispatch()
{
   COleDispatchDriver disp;
   COleException* pe = new COleException;

   try 
   {
      // Create instance of Microsoft System Information Control  
      // by using ProgID. 
      if (disp.CreateDispatch(_T("WMPlayer.OCX"), pe))
      {
         //Get uiMode.     
         CString strUIMode;
         disp.InvokeHelper(23, DISPATCH_PROPERTYGET, VT_BSTR, 
            (void*)&strUIMode, NULL);            

         CString strMsg;
         strMsg.Format(_T("WMP uiMode is %s."), strUIMode);
         AfxMessageBox(strMsg);
      }
      else
      {
         throw pe;
      }
   }
   //Catch control-specific exceptions. 
    catch (COleDispatchException* pe) 
   {
      CString cStr;

      if (!pe->m_strSource.IsEmpty())
         cStr = pe->m_strSource + _T(" - ");
      if (!pe->m_strDescription.IsEmpty())
         cStr += pe->m_strDescription;
      else
         cStr += _T("unknown error");

      AfxMessageBox(cStr, MB_OK, 
         (pe->m_strHelpFile.IsEmpty()) ?  0 : pe->m_dwHelpContext);

      pe->Delete();
   }
   //Catch all MFC exceptions, including COleExceptions. 
   // OS exceptions will not be caught. 
   catch (CException* pe) 
   {
      TRACE(_T("%s(%d): OLE Execption caught: SCODE = %x"), 
         __FILE__, __LINE__, COleException::Process(pe));
      pe->Delete();
   }

   pe->Delete();
}

요구 사항

헤더: afxdisp.h

참고 항목

참조

COleDispatchDriver 클래스

계층 구조 차트

COleDispatchDriver::DetachDispatch

COleDispatchDriver::ReleaseDispatch

COleDispatchDriver::AttachDispatch

COleException 클래스

COleDispatchDriver::m_lpDispatch