1. 打印应用层程序崩溃的Dump信息:
LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
WCHAR strDumpFile[1024];
SYSTEMTIME time;
GetLocalTime (&time);
wsprintf (strDumpFile, L"%s[%d-%d-%d %d.%d.%d].%s", L"dump", time.wYear, time.wMonth, time.wDay,time.wHour, time.wMonth, time.wSecond, L"dmp");
HANDLE hFile = CreateFile(strDumpFile,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile!=INVALID_HANDLE_VALUE)
{
MINIDUMP_EXCEPTION_INFORMATION ExInfo;
ExInfo.ThreadId= ::GetCurrentThreadId();
ExInfo.ExceptionPointers = ExceptionInfo;
ExInfo.ClientPointers = NULL;
BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(),
GetCurrentProcessId(),
hFile,
MiniDumpNormal,
&ExInfo,
NULL,
NULL );
CloseHandle(hFile);
}
return EXCEPTION_EXECUTE_HANDLER;
}
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
2. CRT 可能截获SetUnhandledExceptionFilter 使应用程序无法打印dump 信息。
_set_abort_behavior();
_set_invalid_parameter_handler();
Hook SetUnhandledExceptionFilter 提前获得设置权限。