SceneHandler *GELEngine = NULL; LONG WINAPI TopLevelFilter(struct _EXCEPTION_POINTERS *ExceptionInfo) { LONG rc = EXCEPTION_CONTINUE_SEARCH; HMODULE DllHandle = NULL; String DumpFileName; String ErrorMessage; MINIDUMPWRITEDUMP MiniDump; HANDLE DumpFile; char Str[MAX_PATH]; bool ReadyToReport = false; if (GetModuleFileName(NULL, Str, MAX_PATH)) { // Get the Absolute Path of the EXE and put the DumpFile.dmp there. PathRemoveFileSpec(Str); DumpFileName = Str; DumpFileName.append("\\CrashReport.dmp"); } // Load the Debug Help library to help us with a stack trace DllHandle = LoadLibrary("DBGHELP.DLL"); if (DllHandle) { // Get the address of the MiniDumpWriteDump() function inside the library MiniDump = (MINIDUMPWRITEDUMP) GetProcAddress(DllHandle, "MiniDumpWriteDump"); if (MiniDump) { // create the file DumpFile = CreateFile(DumpFileName.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (DumpFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = GetCurrentThreadId(); ExInfo.ExceptionPointers = ExceptionInfo; ExInfo.ClientPointers = NULL; // Write the information into the dump if (MiniDump(GetCurrentProcess(), GetCurrentProcessId(), DumpFile, MiniDumpNormal, &ExInfo, NULL, NULL)) { ReadyToReport = true; rc = EXCEPTION_EXECUTE_HANDLER; }else{ ErrorMessage = "Failed to save dump file to CrashReport.dmp."; } CloseHandle(DumpFile); if (ReadyToReport) { // **********Report that a crash has happened********** } }else{ ErrorMessage = "Cannot create CrashReport.dmp. File I/O error!"; } }else{ ErrorMessage = "Failed to attach to MiniDumpWriteDump(). DBGHELP.DLL might be too old?"; } }else{ ErrorMessage = "DBGHELP.DLL not found."; } if (ErrorMessage.size() > 0) { MessageBox(NULL, ErrorMessage.c_str(), GEL_ENGINE_NAME, MB_OK); } return rc; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #ifdef _DEBUG _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF); #endif __try { // Attempt to create a Game Object GELEngine = new SceneHandler(hInstance, hPrevInstance, lpCmdLine, nCmdShow); // Run the Game if (GELEngine) { GELEngine->Loop(); // Delete the Game Engine SAFE_DELETE(GELEngine); } } __except(TopLevelFilter(GetExceptionInformation())) { // An Error has occurred, delete the objects in memory if (GELEngine) { // Delete the Game Engine SAFE_DELETE(GELEngine); } return 0; } #ifdef _DEBUG if (_CrtDumpMemoryLeaks()) { MessageBox(NULL, "Memory Leak Detected!", "Warning!", MB_OK); } #endif return 0; }