#include <Windows.h>
#include <DbgHelp.h>
#pragma comment(lib,"DbgHelp.lib")
//创建dump文件
void CreateDumpFile(CString lpstrDumpFilePathName, EXCEPTION_POINTERS* pException)
{
HANDLE hDumpFile = CreateFile(lpstrDumpFilePathName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
// Dump信息
MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
dumpInfo.ExceptionPointers = pException;
dumpInfo.ThreadId = GetCurrentThreadId();
dumpInfo.ClientPointers = TRUE;
// 写入dump文件
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);
CloseHandle(hDumpFile);
}
// 处理Unhandled Excepiton 的回调函数
LONG ApplicationCrashHandler(EXCEPTION_POINTERS* pException)
{
SYSTEMTIME time;
GetLocalTime(&time);
CString strDmpName;
strDmpName.Format(L"%02d%02d_%02d%02d%02d.dmp", time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
strDmpName = L"C:\\Users\\123\\Desktop\\新建文件夹 (11)\\" + strDmpName;
CreateDumpFile(strDmpName, pException);
return EXCEPTION_EXECUTE_HANDLER;
}
//调用
void main()
{
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler);
}
文章评论