#include "stdafx.h" #include <stdio.h> #include <time.h> #include <windows.h> #include <DbgHelp.h> #pragma comment(lib, "DbgHelp.lib") LONG WINAPI TopLevelFilter( struct _EXCEPTION_POINTERS *pExceptionInfo ) { LONG ret = EXCEPTION_CONTINUE_SEARCH; time_t nowtime; time(&nowtime); struct tm *pTime = localtime(&nowtime); char szFile[128] = {0}; sprintf(szFile, "%4d.%02d.%02d_%02d.%02d.%02d.dmp", pTime->tm_year+1900, pTime->tm_mon+1, pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec); HANDLE hFile = ::CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = ::GetCurrentThreadId(); ExInfo.ExceptionPointers = pExceptionInfo; ExInfo.ClientPointers = NULL; MINIDUMP_TYPE MiniDumpWithDataSegs = MiniDumpNormal ; // write the dump BOOL bOK = MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithDataSegs, &ExInfo, NULL, NULL ); ret = EXCEPTION_EXECUTE_HANDLER; ::CloseHandle(hFile); } return ret; } void ExpTest5(){ char *p = NULL; p[0] = 0; } void TestExceptionWalking() { ExpTest5(); } int main() { ::SetUnhandledExceptionFilter(TopLevelFilter); TestExceptionWalking(); return 0; } 以上是具体代码 可以直接运行