包含如下头文件 和 引用Lib库
#include <dbghelp.h> #pragma comment(lib, "dbghelp.lib")定义
LONG WINAPI MyUnhandledFilter(struct _EXCEPTION_POINTERS *lpExceptionInfo) { LONG ret = EXCEPTION_EXECUTE_HANDLER; TCHAR szFileName[64]; SYSTEMTIME st; ::GetLocalTime(&st); wsprintf(szFileName, TEXT("TCP_ddd-ddd-%ld-%ld.dmp"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, GetCurrentProcessId(), GetCurrentThreadId()); 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 BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL ); ::CloseHandle(hFile); } else { //printf("Create File %s Failed %d\n", szFileName, GetLastError()); } ::MessageBox(NULL, "程序遇到问题需要关闭!", "提示", MB_OK); return ret; }在程序初始化的时候 设置如下语句 SetUnhandledExceptionFilter(&MyUnhandledFilter);