首先在合适的地方调用
LPTOP_LEVEL_EXCEPTION_FILTER pOdk = SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
MyUnhandledExceptionFilter的实现如下:
LONG WINAPI MyUnhandledExceptionFilter( __in struct _EXCEPTION_POINTERS* ExceptionInfo ) { HANDLE hFile = CreateFile("mini.dmp", // name of the write GENERIC_WRITE, // open for writing 0, // do not share NULL, // default security CREATE_ALWAYS, // overwrite existing FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template MINIDUMP_EXCEPTION_INFORMATION expInfo; expInfo.ThreadId = ::GetCurrentThreadId(); expInfo.ExceptionPointers = ExceptionInfo; expInfo.ClientPointers = TRUE; MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), hFile, MiniDumpNormal , &expInfo, NULL, NULL); CloseHandle(hFile); AfxMessageBox("dddd"); return EXCEPTION_CONTINUE_SEARCH; }
这样程序崩溃时会在当前目录生成一个mini.dmp文件,有了它,就可以很方便的调试了
记得加入
#include <DbgHelp.h> #pragma comment(lib, "Dbghelp.lib")