다음을 통해 공유


_set_com_error_handler

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

구문

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;
}
Exception raised: Unable to establish the connection!

요구 사항

헤더:<comdef.h>

Lib: /Zc:wchar_t 컴파일러 옵션이 지정된 경우(기본값) comsuppw.lib 또는 comsuppwd.lib를 사용합니다. /Zc:wchar_t- 컴파일러 옵션이 지정된 경우 comsupp.lib를 사용합니다. IDE 에서 이 옵션을 설정하는 방법을 비롯한 자세한 내용은 /Zc:wchar_t(wchar_t 네이티브 형식)을 참조하세요.

참고 항목

컴파일러 COM 전역 함수