1:分析程序异常等等信息,在入口处初始化即可
//生成Dump文件信息 OS:Windows #pragma once #include <windows.h> #include <imagehlp.h> #if (_MSC_VER < 1700) // vs2010 and before version #include <stdlib.h> #else #include <tchar.h> #endif #include <ctime> #include <cstdio> #pragma comment(lib, "dbghelp.lib") class MiniDump { public: MiniDump() = delete; ~MiniDump() = delete; static LONG WINAPI RunUnhandledFilter(struct _EXCEPTION_POINTERS *lpExceptionInfo) { LONG ret = EXCEPTION_EXECUTE_HANDLER; TCHAR szFileName[64]; SYSTEMTIME st; ::GetLocalTime(&st); std::srand(static_cast<unsigned int>(std::time(0))); #if defined(UNICODE) swprintf_s(szFileName, L"%d-%d-%d-%d-%d-%d-%d-%d.dmp", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, std::rand()); #else sprintf_s(szFileName, "%d-%d-%d-%d-%d-%d-%d-%d.dmp", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, std::rand()); #endif HANDLE hFile = ::CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = ::GetCurrentThreadId(); ExInfo.ExceptionPointers = lpExceptionInfo; ExInfo.ClientPointers = false; // write the dump #if !defined(FINALIDEALSEE) BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &ExInfo, NULL, NULL); #else BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL); #endif if (bOK) { printf("Create Dump File Success!\n"); } else { printf("MiniDumpWriteDump Failed: %d\n", GetLastError()); } ::CloseHandle(hFile); } else { #if defined(UNICODE) wprintf(L"Create File %ls Failed %d\n", szFileName, GetLastError()); #else printf("Create File %s Failed %d\n", szFileName, GetLastError()); #endif } //禁用对话框提示信息// //FatalAppExit(-1, _T("Fatal Error, Check Dump File")); return ret; } static void InitMinDump() { SetUnhandledExceptionFilter(RunUnhandledFilter); } };
作者:长风
Email:844064492@qq.com
QQ群:607717453
Git:https://github.com/zhaohu19910409Dz
开源项目:https://github.com/OriginMEK/MEK
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
感谢您的阅读。如果觉得有用的就请各位大神高抬贵手“推荐一下”吧!你的精神支持是博主强大的写作动力。
如果觉得我的博客有意思,欢迎点击首页左上角的“+加关注”按钮关注我!