16,473
社区成员
发帖
与我相关
我的任务
分享
#pragma once
#include <dbghelp.h>
#include <shellapi.h>
#include <shlobj.h>
#pragma comment( lib, "DbgHelp")
static LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
char lFilePath[MAX_PATH]="";
GetModuleFileName(NULL, lFilePath, MAX_PATH);
strncat(lFilePath, ".dmp", MAX_PATH);
HANDLE lhDumpFile = CreateFile(lFilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL ,NULL);
MINIDUMP_EXCEPTION_INFORMATION loExceptionInfo;
loExceptionInfo.ExceptionPointers = ExceptionInfo;
loExceptionInfo.ThreadId = GetCurrentThreadId();
loExceptionInfo.ClientPointers = TRUE;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),lhDumpFile, MiniDumpWithFullMemory, &loExceptionInfo, NULL, NULL);
CloseHandle(lhDumpFile);
::ShellExecuteW(NULL, NULL, L"BugReport.exe", NULL, NULL, SW_NORMAL);
TerminateProcess(GetCurrentProcess(),0);
return EXCEPTION_EXECUTE_HANDLER;
}
在入口函数调用这句就可以了
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
这样,程序崩溃了,就会生成一个DMP文件,相当实用。