diff options
author | glx <glx@openttd.org> | 2007-08-19 21:51:36 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2007-08-19 21:51:36 +0000 |
commit | ffdbaad8ec18961b456bc3d269187773119c6178 (patch) | |
tree | 0d18269335db35f24ed472e83b7290118fc45a31 | |
parent | a66008f04cbb7a99547839ea6be19d6ddf5170c0 (diff) | |
download | openttd-ffdbaad8ec18961b456bc3d269187773119c6178.tar.xz |
(svn r10948) -Add: [win32] crash.dmp support for MSVC release builds
-rw-r--r-- | src/win32.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/win32.cpp b/src/win32.cpp index 892f724c1..e6106cad0 100644 --- a/src/win32.cpp +++ b/src/win32.cpp @@ -29,6 +29,9 @@ #include <sys/types.h> #include <sys/stat.h> #include <shlobj.h> +#if defined(_MSC_VER) && !defined(WINCE) + #include <dbghelp.h> +#endif static bool _has_console; @@ -592,6 +595,41 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) } } +#if !defined(_DEBUG) + HMODULE dbghelp = LoadLibrary(_T("dbghelp.dll")); + if (dbghelp != NULL) { + typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE, + MINIDUMP_TYPE, + CONST PMINIDUMP_EXCEPTION_INFORMATION, + CONST PMINIDUMP_USER_STREAM_INFORMATION, + CONST PMINIDUMP_CALLBACK_INFORMATION); + MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump"); + if (funcMiniDumpWriteDump != NULL) { + HANDLE file = CreateFile(_T("crash.dmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + HANDLE proc = GetCurrentProcess(); + DWORD procid = GetCurrentProcessId(); + MINIDUMP_EXCEPTION_INFORMATION mdei; + MINIDUMP_USER_STREAM userstream; + MINIDUMP_USER_STREAM_INFORMATION musi; + char msg[] = "****** Built on " __DATE__ " " __TIME__ ". ******"; + + userstream.Type = LastReservedStream + 1; + userstream.Buffer = msg; + userstream.BufferSize = sizeof(msg); + + musi.UserStreamCount = 1; + musi.UserStreamArray = &userstream; + + mdei.ThreadId = GetCurrentThreadId(); + mdei.ExceptionPointers = ep; + mdei.ClientPointers = false; + + funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, NULL); + } + FreeLibrary(dbghelp); + } +#endif + /* Close any possible log files */ CloseConsoleLogIfActive(); |