Código
typedef enum _MINIDUMP_TYPE { MiniDumpNormal = 0x00000000, MiniDumpWithDataSegs = 0x00000001, MiniDumpWithFullMemory = 0x00000002, MiniDumpWithHandleData = 0x00000004, MiniDumpFilterMemory = 0x00000008, MiniDumpScanMemory = 0x00000010, MiniDumpWithUnloadedModules = 0x00000020, MiniDumpWithIndirectlyReferencedMemory = 0x00000040, MiniDumpFilterModulePaths = 0x00000080, MiniDumpWithProcessThreadData = 0x00000100, MiniDumpWithPrivateReadWriteMemory = 0x00000200, MiniDumpWithoutOptionalData = 0x00000400, MiniDumpWithFullMemoryInfo = 0x00000800, MiniDumpWithThreadInfo = 0x00001000, MiniDumpWithCodeSegs = 0x00002000, MiniDumpWithoutAuxiliaryState = 0x00004000, MiniDumpWithFullAuxiliaryState = 0x00008000, MiniDumpWithPrivateWriteCopyMemory = 0x00010000, MiniDumpIgnoreInaccessibleMemory = 0x00020000, MiniDumpWithTokenInformation = 0x00040000 } MINIDUMP_TYPE; typedef struct _MINIDUMP_EXCEPTION_INFORMATION { DWORD ThreadId; PEXCEPTION_POINTERS ExceptionPointers; BOOL ClientPointers; } MINIDUMP_EXCEPTION_INFORMATION, *PMINIDUMP_EXCEPTION_INFORMATION; typedef struct _MINIDUMP_USER_STREAM { ULONG32 Type; ULONG BufferSize; PVOID Buffer; } MINIDUMP_USER_STREAM, *PMINIDUMP_USER_STREAM; typedef struct _MINIDUMP_USER_STREAM_INFORMATION { ULONG UserStreamCount; PMINIDUMP_USER_STREAM UserStreamArray; } MINIDUMP_USER_STREAM_INFORMATION, *PMINIDUMP_USER_STREAM_INFORMATION; typedef struct _MINIDUMP_CALLBACK_INFORMATION { PVOID CallbackRoutine; PVOID CallbackParam; } MINIDUMP_CALLBACK_INFORMATION, *PMINIDUMP_CALLBACK_INFORMATION; typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE,MINIDUMP_TYPE, CONST PMINIDUMP_EXCEPTION_INFORMATION, CONST PMINIDUMP_USER_STREAM_INFORMATION, CONST PMINIDUMP_CALLBACK_INFORMATION ); LONG WINAPI MiniDumper(struct _EXCEPTION_POINTERS *pExceptionInfo){ LONG retval=EXCEPTION_CONTINUE_SEARCH; HMODULE hDll=LoadLibrary("dbghelp.dll"); if(hDll){ MiniDumpWriteDump_t MiniDumpWriteDump=(MiniDumpWriteDump_t) GetProcAddress(hDll,"MiniDumpWriteDump")); if(MiniDumpWriteDump){ char szDumpPath[MAX_PATH];SYSTEMTIME sSystemTime; if(GetModuleFileName(NULL,szDumpPath,MAX_PATH)){ if(pSlash)*++pSlash=0; }else GetTempPath(MAX_PATH,szDumpPath); GetLocalTime(&sSystemTime); sprintf(szDumpPath,"%s%s_%02i_%02i_%04i__%02i_%02i_%02i.mdmp",szDumpPath,"MyProcess",sSystemTime.wDay,sSystemTime.wMonth,sSystemTime.wYear,sSystemTime.wHour,sSystemTime.wMinute,sSystemTime.wSecond); HANDLE hFile=CreateFile(szDumpPath,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=FALSE if(MiniDumpWriteDump(GetCurrentProcess(),GetCurrentProcessId(),hFile,MiniDumpNormal,&ExInfo,NULL,NULL)) retval=EXCEPTION_EXECUTE_HANDLER; CloseHandle(hFile); } } } return retval; }
y luego al principio de tu programa agregas:
Código
SetUnhandledExceptionFilter(MiniDumper);
de esa forma cuando ocurra un error se generará un archivo que contendrá información del mismo (el cual lo puedes analizar con Windbg)...
S2