_set_com_error_handler

Microsoft 전용

COM 오류 처리에 사용되는 기본 함수를 대체합니다.

void __stdcall _set_com_error_handler(
   void (__stdcall *pHandler)(
      HRESULT hr, 
      IErrorInfo* perrinfo
   )
);

매개 변수

  • pHandler
    대체 함수에 대한 포인터입니다.

  • hr
    HRESULT 정보.

  • perrinfo
    IErrorInfo 개체

설명

기본적으로 _com_raise_error는 모든 COM 오류를 처리합니다._set_com_error_handler를 사용하여 이 동작을 변경하여 사용자 고유의 오류 처리 함수를 호출할 수 있습니다.

대체 함수에는 _com_raise_error에 해당하는 서명이 있어야 합니다.

예제

// _set_com_error_handler.cpp
// compile with /EHsc
#include <stdio.h>
#include <comdef.h>
#include <comutil.h>

// Importing ado dll to attempt to establish an ado connection.
// Not related to _set_com_error_handler 
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")

void __stdcall _My_com_raise_error(HRESULT hr, IErrorInfo* perrinfo)
{
   throw "Unable to establish the connection!";
}

int main()
{
   _set_com_error_handler(_My_com_raise_error);
   _bstr_t bstrEmpty(L"");
   _ConnectionPtr Connection = NULL;
   try
   {
      Connection.CreateInstance(__uuidof(Connection));
      Connection->Open(bstrEmpty, bstrEmpty, bstrEmpty, 0); 
   }
   catch(char* errorMessage)
   {
      printf("Exception raised: %s\n", errorMessage);
   }

   return 0;
}
  

요구 사항

헤더: comdef.h

Lib: "네이티브 형식 wchar_t는" 컴파일러 옵션이 선택 되어 있으면 comsuppw.lib 또는 comsuppwd.lib를 사용 합니다."Wchar_t를 네이티브 형식" 이면 off, comsupp.lib를 사용 합니다.자세한 내용은 /Zc:wchar_t(wchar_t를 네이티브 형식으로 인식)를 참조하십시오.

참고 항목

참조

컴파일러 COM 전역 함수