When my program crashes it creates a minidump, from the unhandled exception handler. The issue I'm having is that people are sending me crash dumps, but when I try to open them in Visual Studio 2010 it says they're corrupt ("The dump file has an invalid format"). I'm not distributing dbghelp.dll
with my program, do I need to? I assume that if it's a version issue, Visual Studio would let me know and not output the above message.
The code I use to generate the logs is
LONG WINAPI OnUnhandledException(PEXCEPTION_POINTERS pExceptionInfo)
{
MINIDUMP_EXCEPTION_INFORMATION ei;
ei.ExceptionPointers = pExceptionInfo;
ei.ThreadId = GetCurrentThreadId();
ei.ClientPointers = FALSE;
DWORD dwProcessId = GetCurrentProcessId();
SYSTEMTIME stLocalTime;
GetLocalTime(&stLocalTime);
wchar_t CrashDumpW[1024];
swprintf_s(CrashDumpW, NELEMS(CrashDumpW),
L"%s\\%s-%s-%04X-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp",
g_CrashDirectory.c_str(), L"Program", MAJOR_VERSION_STR,
INTERNAL_VERSION, stLocalTime.wYear, stLocalTime.wMonth,
stLocalTime.wDay, stLocalTime.wHour, stLocalTime.wMinute,
stLocalTime.wSecond, dwProcessId, ei.ThreadId);
HANDLE hFile = CreateFileW(CrashDumpW, GENERIC_READ | GENERIC_WRITE,
NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
MiniDumpWriteDump(GetCurrentProcess(), dwProcessId, hFile,
MiniDumpScanMemory, &ei, NULL, NULL);
CloseHandle(hFile);
return EXCEPTION_EXECUTE_HANDLER;
}
This can be caused by someone debugging your process. I have noticed that if a process has a debugger attached, the minidumps it produces are often corrupted exactly the same way. They are less in size than the ones produced normally.
Since you return
EXCEPTION_EXECUTE_HANDLER
from your handler, the default unhandled exception handler is executed after yours, which may cause DrWatson come into play and attach to your process as a debugger.