_set_com_error_handler
COM のエラー処理に使用する既定の関数を置き換えます。 _set_com_error_handler は Microsoft 固有です。
構文
void __stdcall _set_com_error_handler(
void (__stdcall *pHandler)(
HRESULT hr,
IErrorInfo* perrinfo
)
);
パラメーター
pHandler
置換する関数へのポインター。
人事
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 はネイティブ型)」を参照してください。
関連項目
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示