Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Debug EXE
Friday, August 24th, 2007 at 11:20:04am MDT 

  1. SceneHandler *GELEngine = NULL;
  2.  
  3. LONG WINAPI TopLevelFilter(struct _EXCEPTION_POINTERS *ExceptionInfo)
  4. {
  5.         LONG rc = EXCEPTION_CONTINUE_SEARCH;
  6.         HMODULE DllHandle = NULL;
  7.         String DumpFileName;
  8.         String ErrorMessage;
  9.         MINIDUMPWRITEDUMP MiniDump;
  10.         HANDLE DumpFile;
  11.         char Str[MAX_PATH];
  12.         bool ReadyToReport = false;
  13.  
  14.         if (GetModuleFileName(NULL, Str, MAX_PATH))
  15.         {
  16.                 // Get the Absolute Path of the EXE and put the DumpFile.dmp there.
  17.                 PathRemoveFileSpec(Str);
  18.                 DumpFileName = Str;
  19.                 DumpFileName.append("\\CrashReport.dmp");
  20.         }
  21.  
  22.         // Load the Debug Help library to help us with a stack trace
  23.         DllHandle = LoadLibrary("DBGHELP.DLL");
  24.  
  25.         if (DllHandle)
  26.         {
  27.                 // Get the address of the MiniDumpWriteDump() function inside the library
  28.                 MiniDump = (MINIDUMPWRITEDUMP) GetProcAddress(DllHandle, "MiniDumpWriteDump");
  29.  
  30.                 if (MiniDump)
  31.                 {
  32.                         // create the file
  33.                         DumpFile = CreateFile(DumpFileName.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  34.  
  35.                         if (DumpFile != INVALID_HANDLE_VALUE)
  36.                         {
  37.                                 MINIDUMP_EXCEPTION_INFORMATION ExInfo;
  38.  
  39.                                 ExInfo.ThreadId = GetCurrentThreadId();
  40.                                 ExInfo.ExceptionPointers = ExceptionInfo;
  41.                                 ExInfo.ClientPointers = NULL;
  42.  
  43.                                 // Write the information into the dump
  44.                                 if (MiniDump(GetCurrentProcess(), GetCurrentProcessId(), DumpFile, MiniDumpNormal, &ExInfo, NULL, NULL))
  45.                                 {
  46.                                         ReadyToReport = true;
  47.                                         rc = EXCEPTION_EXECUTE_HANDLER;
  48.                                 }else{
  49.                                         ErrorMessage = "Failed to save dump file to CrashReport.dmp.";
  50.                                 }
  51.                                
  52.                                 CloseHandle(DumpFile);
  53.  
  54.                                 if (ReadyToReport)
  55.                                 {
  56.                                         // **********Report that a crash has happened**********
  57.                                 }
  58.                         }else{
  59.                                 ErrorMessage = "Cannot create CrashReport.dmp. File I/O error!";
  60.                         }
  61.  
  62.                 }else{
  63.                         ErrorMessage = "Failed to attach to MiniDumpWriteDump(). DBGHELP.DLL might be too old?";
  64.                 }
  65.         }else{
  66.                 ErrorMessage = "DBGHELP.DLL not found.";
  67.         }
  68.  
  69.         if (ErrorMessage.size() > 0)
  70.         {
  71.                 MessageBox(NULL, ErrorMessage.c_str(), GEL_ENGINE_NAME, MB_OK);
  72.         }
  73.  
  74.         return rc;
  75. }
  76.  
  77. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  78. {
  79.         #ifdef _DEBUG
  80.                 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF);
  81.         #endif
  82.  
  83.         __try
  84.         {
  85.                 // Attempt to create a Game Object
  86.                 GELEngine = new SceneHandler(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  87.  
  88.                 // Run the Game
  89.                 if (GELEngine)
  90.                 {
  91.                         GELEngine->Loop();
  92.  
  93.                         // Delete the Game Engine
  94.                         SAFE_DELETE(GELEngine);
  95.                 }
  96.  
  97.         } __except(TopLevelFilter(GetExceptionInformation()))
  98.         {
  99.                 // An Error has occurred, delete the objects in memory
  100.                 if (GELEngine)
  101.                 {
  102.                         // Delete the Game Engine
  103.                         SAFE_DELETE(GELEngine);
  104.                 }
  105.  
  106.                 return 0;
  107.         }
  108.  
  109.         #ifdef _DEBUG
  110.                 if (_CrtDumpMemoryLeaks())
  111.                 {
  112.                         MessageBox(NULL, "Memory Leak Detected!", "Warning!", MB_OK);
  113.                 }
  114.         #endif
  115.  
  116.         return 0;
  117. }

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right