由于昨天太晚 沒有看完 今天繼續看 繼續轉
原帖地址
http://blog.csdn.net/vagrxie/archive/2009/07/31/4398721.aspx 今天要轉的就是 SEH + MiniDump 實現既Dump文件 又讓程序繼續運行
1 #include "stdafx.h"
2 #include <windows.h>
3 #include <Dbghelp.h>
4 using namespace std;
5
6 #pragma auto_inline (off)
7 #pragma comment( lib, "DbgHelp" )
8
9 // 為了程序的簡潔和集中關注關心的東西,按示例程序的慣例忽略錯誤檢查,實際使用時請注意
10
11 LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo )
12 {
13 HANDLE lhDumpFile = CreateFile(_T("DumpFile.dmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL ,NULL);
14 MINIDUMP_EXCEPTION_INFORMATION loExceptionInfo;
15 loExceptionInfo.ExceptionPointers = ExceptionInfo;
16 loExceptionInfo.ThreadId = GetCurrentThreadId();
17 loExceptionInfo.ClientPointers = TRUE;
18 MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),lhDumpFile, MiniDumpNormal, &loExceptionInfo, NULL, NULL);
19 CloseHandle(lhDumpFile);
20 return EXCEPTION_EXECUTE_HANDLER;
21 }
22
23 void Fun2()
24 {
25 __try
26 {
27 static bool b = false;
28 if(!b)
29 {
30 b = true;
31 int *p = NULL;
32 *p = 0;
33 }
34 else
35 {
36 MessageBox(NULL, _T("Here"), _T(""), MB_OK);
37 }
38 }
39 __except(MyUnhandledExceptionFilter(GetExceptionInformation()))
40 {
41 }
42 }
43
44 void Fun()
45 {
46 Fun2();
47 }
48
49 int main()
50 {
51 Fun();
52 Fun(); //用于顯示MessageBox
53 return 1;
54 }
55
56
最后轉一句話
Make it right before you make it faster.
Keep it right when you make it faster.
Make it clear before you make it faster.
Do not sacrifice clarity for small gains in efficiency.
posted on 2009-08-28 09:16
李佳 閱讀(588)
評論(0) 編輯 收藏 引用 所屬分類:
調試技巧