1 lib配置 项目-->属性-->配置属性-->链接器-->输入-->附加依赖项 增加dbghelp.lib
2 头文件
#include <imagehlp.h>
#include <Windows.h>
3 main函数
在第一行调用window api:SetUnhandledExceptionFilter(UnhandledExceptionFilter2);
4 UnhandledExceptionFilter2的实现
LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
string strDumpFile = "exception.dmp ";
HANDLE hFile = CreateFile(strDumpFile.c_str(), 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;
// write the dump
BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &ExInfo, NULL, NULL );
CloseHandle(hFile);
}
return EXCEPTION_EXECUTE_HANDLER;
}
来源:CSDN
作者:晚餐吃什么
链接:https://blog.csdn.net/Think88666/article/details/103897036