posts - 23,  comments - 20,  trackbacks - 0
由于昨天太晚 没有看完 今天继续看  继续转
原帖地址
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 *= NULL;
32             *= 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 李佳 阅读(568) 评论(0)  编辑 收藏 引用 所属分类: 调试技巧

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年8月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿

随笔分类

随笔档案

文章档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜