标签:
1 #ifndef _DUMP_GENERATE_H_ 2 #define _DUMP_GENERATE_H_ 3 4 #include <Windows.h> 5 #include <DbgHelp.h> 6 #pragma comment(lib, "DbgHelp.lib") 7 8 LONG WINAPI MyUnhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS *ExceptionInfo); 9 void MyDumpGenerate(); 10 11 void MyDumpGenerate() 12 { 13 SetUnhandledExceptionFilter(MyUnhandledExceptionFilter); 14 } 15 16 LONG WINAPI MyUnhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS *ExceptionInfo) 17 { 18 MessageBox(0,L"DumpGenerate",0,0); 19 20 HANDLE lhDumpFile = CreateFile(L"D:\\test.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL); 21 22 MINIDUMP_EXCEPTION_INFORMATION loExceptionInfo; 23 loExceptionInfo.ExceptionPointers = ExceptionInfo; 24 loExceptionInfo.ThreadId = GetCurrentThreadId(); 25 loExceptionInfo.ClientPointers = TRUE; 26 MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), lhDumpFile, MiniDumpNormal, &loExceptionInfo, NULL, NULL); 27 28 CloseHandle(lhDumpFile); 29 30 /* 31 * EXCEPTION_CONTINUE_SEARCH:将异常传给调试器 32 * EXCEPTION_EXECUTE_HANDLER:不显示错误信息 33 */ 34 return EXCEPTION_EXECUTE_HANDLER; 35 } 36 37 #endif // _DUMP_GENERATE_H_ 38 39 //////////////// 40 // main.cpp 41 int main() 42 { 43 MyDumpGenerate(); 44 int* p = NULL; 45 *p = 1; 46 // 这里异常后,会自动调用MyUnhandledExceptionFilter接口,生成dump文件:test.dmp。 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/nchxmoon/p/4390980.html