WIP, minidump is done in another program, started from our app.
The other program is not in git yet.
This commit is contained in:
+45
-4
@@ -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<std::uintptr_t>(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
|
||||
}
|
||||
Reference in New Issue
Block a user