OutputDebugStringA
は例外DBG_PRINTEXCEPTION_C
(win10でW
バージョン - DBG_PRINTEXCEPTION_WIDE_C
)を生成し、結果として、我々は、この例外を自分で処理することができます(この例外のためのシステム・デフォルト・ハンドラthisを行う - - (文字+ 1での文字列の長さ、文字列ポインタ)2つの引数で)。コンソールにリダイレクトOutputDebugString
ため
例ハンドラ:
LONG NTAPI VexHandler(PEXCEPTION_POINTERS ExceptionInfo)
{
PEXCEPTION_RECORD ExceptionRecord = ExceptionInfo->ExceptionRecord;
switch (ExceptionRecord->ExceptionCode)
{
case DBG_PRINTEXCEPTION_WIDE_C:
case DBG_PRINTEXCEPTION_C:
if (ExceptionRecord->NumberParameters >= 2)
{
ULONG len = (ULONG)ExceptionRecord->ExceptionInformation[0];
union {
ULONG_PTR up;
PCWSTR pwz;
PCSTR psz;
};
up = ExceptionRecord->ExceptionInformation[1];
HANDLE hOut = GetStdHandle(STD_ERROR_HANDLE);
if (ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C)
{
// localized text will be incorrect displayed, if used not CP_OEMCP encoding
// WriteConsoleA(hOut, psz, len, &len, 0);
// assume CP_ACP encoding
if (ULONG n = MultiByteToWideChar(CP_ACP, 0, psz, len, 0, 0))
{
PWSTR wz = (PWSTR)alloca(n * sizeof(WCHAR));
if (len = MultiByteToWideChar(CP_ACP, 0, psz, len, wz, n))
{
pwz = wz;
}
}
}
if (len)
{
WriteConsoleW(hOut, pwz, len - 1, &len, 0);
}
}
return EXCEPTION_CONTINUE_EXECUTION;
}
return EXCEPTION_CONTINUE_SEARCH;
}
とセットのために、このハンドラがコールする必要が:
AddVectoredExceptionHandler(TRUE, VexHandler);
をhereようOutputDebugString
のシステムの実装 - それは本当にとRaiseException
と呼ばれますこの引数は、例外ハンドラでのみ代わりにMessageBox
- 012と記載されているコード。
DBG_PRINTEXCEPTION_ [WIDE_のために 'VEX'ハンドラとスパイを設定する必要がある場合は、dbgviewを試してみてください。他にも多くの機能を持っています。 –
" ] C ' - あなたがコンソールに' OutputDebugString'をリダイレクトするためのコードを貼り付けることができれば - これは小さくて単純に – RbMm
@RbMm確かに - それは役に立つかもしれません。 – Zitrax