You can write a minidump with the following code, if you have a exception. If you want to have "heap" informations, you need to use MiniDumpWithFullMemory
:
typedef BOOL (__stdcall *tMDWD)(
IN HANDLE hProcess,
IN DWORD ProcessId,
IN HANDLE hFile,
IN MINIDUMP_TYPE DumpType,
IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
//IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam OPTIONAL
IN CONST PVOID UserStreamParam OPTIONAL,
//IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL
IN CONST PVOID CallbackParam OPTIONAL
);
static int WriteMiniDump(LPCTSTR szFN, struct _EXCEPTION_POINTERS *ep, MINIDUMP_TYPE miniDumpType = MiniDumpWithFullMemory)
{
int ret = EXCEPTION_EXECUTE_HANDLER;
HANDLE hFile;
static tMDWD pMDWD = NULL;
if (pMDWD == NULL)
{
HMODULE hdbghelpmod = LoadLibrary(_T("dbghelp.dll"));
if (hdbghelpmod == NULL)
return ret;
pMDWD = (tMDWD) GetProcAddress(hdbghelpmod, "MiniDumpWriteDump");
}
if (pMDWD == NULL)
return ret;
hFile = CreateFile(szFN,
GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
MINIDUMP_EXCEPTION_INFORMATION stMDEI;
stMDEI.ThreadId = GetCurrentThreadId();
stMDEI.ExceptionPointers = ep;
stMDEI.ClientPointers = TRUE;
// try to create an miniDump:
if (pMDWD(
GetCurrentProcess(),
GetCurrentProcessId(),
hFile,
miniDumpType,
&stMDEI,
NULL,
NULL
) == FALSE)
{
printf("Minidump failed! 0x8.8X\n", GetLastError());
OutputDebugString(_T("Minidump failed!"));
}
else
{ //ret = 0; // suceeded }
CloseHandle(hFile);
}
return ret;
}
Then you can use it like this:
__try
{
fread((char*)0x12, 0x10, 1, (FILE*)0x12);
}
__except (WriteMiniDump(_T("c:\\Temp\\MyDump.dmp"), GetExceptionInformation())
{
printf("Handled");
}