From 05bbecc4524848a146a812beb200f739df6e7136 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 24 Feb 2016 17:23:47 +0100 Subject: [PATCH] WIP, minidump is done in another program, started from our app. The other program is not in git yet. --- src/Game/main.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/Game/main.cpp b/src/Game/main.cpp index f69c27d6..1445f9ed 100644 --- a/src/Game/main.cpp +++ b/src/Game/main.cpp @@ -1,4 +1,4 @@ -//#include "Game.h" +#include "Game.h" #include "MiniDump.h" LONG WINAPI CrashHandler(EXCEPTION_POINTERS* pException); @@ -37,9 +37,50 @@ int main(int argc, char* argv[]) LONG WINAPI CrashHandler(EXCEPTION_POINTERS* pException) { - //Take minidump. path should be bin/TacticalZ.dmp - //Then show MessageBox, and exit application. - Create_Dump(pException); + // Get absolute path of current process: C:/ ... /name.exe + CHAR Dump_Path[MAX_PATH]; + GetModuleFileName(NULL, Dump_Path, sizeof(Dump_Path)); + std::string path(Dump_Path); + // Then make the path into C:/ .. /nameDump.exe + // Remove the .exe from path + path = path.substr(0, path.length() - 4); + path += "Dump.exe"; + + DWORD procId = GetCurrentProcessId(); + DWORD threadId = GetCurrentThreadId(); + std::uintptr_t intExcPtr = reinterpret_cast(pException); + std::ostringstream ss; + ss << procId << " " << threadId << " " << intExcPtr; + char cmds[128]; + strcpy(cmds, ss.str().c_str()); + + STARTUPINFO sInfo; + PROCESS_INFORMATION pInfo; + ZeroMemory(&sInfo, sizeof(sInfo)); + ZeroMemory(&pInfo, sizeof(pInfo)); + sInfo.cb = sizeof(sInfo); + + if (CreateProcess(path.c_str(), + cmds, + nullptr, + nullptr, + FALSE, + NORMAL_PRIORITY_CLASS, + nullptr, + nullptr, + &sInfo, + &pInfo) + ) { + WaitForSingleObject(pInfo.hProcess, INFINITE); + CloseHandle(pInfo.hProcess); + CloseHandle(pInfo.hThread); + } else { + HRESULT error = ((HRESULT)GetLastError()) & 0xFFFF; + char hexErrBuf[16]; + std::sprintf(hexErrBuf, "0x%x", error); + std::cout << "Could not create a minidump because CreateProcess failed with error " << hexErrBuf; + MessageBox(NULL, "Application crashed, could not create a memory dump.", "MiniDump", MB_ICONHAND | MB_OK); + } return EXCEPTION_EXECUTE_HANDLER;// EXCEPTION_CONTINUE_SEARCH } \ No newline at end of file