MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / ShowExternalMessageBox

Function ShowExternalMessageBox

TombEngine/Specific/winmain.cpp:266–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264}
265
266void ShowExternalMessageBox(const std::string& text)
267{
268 // Try to locate error message utility resource.
269 HRSRC res = FindResource(NULL, MAKEINTRESOURCE(IDR_CRASHMSG), "EXE");
270 if (!res)
271 return;
272
273 // Load executable, if found.
274 HGLOBAL resData = LoadResource(NULL, res);
275 if (!resData)
276 return;
277
278 // Lock executable resource to get pointer to data.
279 void* resPtr = LockResource(resData);
280 if (!resPtr)
281 return;
282
283 const auto exePath = std::string("crashmsg.exe");
284
285 // Write executable to a disk.
286 HANDLE hFile = CreateFileA(exePath.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
287 if (hFile == INVALID_HANDLE_VALUE)
288 return;
289
290 DWORD written;
291 WriteFile(hFile, resPtr, SizeofResource(NULL, res), &written, NULL);
292 CloseHandle(hFile);
293
294 STARTUPINFOA si = { sizeof(si) };
295 PROCESS_INFORMATION pi;
296
297 // Execute the error message utility with the provided text.
298 std::string cmdLine = "\"" + exePath + "\" " + "\"" + text + "\"";
299 if (CreateProcessA(NULL, cmdLine.data(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
300 {
301 WaitForSingleObject(pi.hProcess, INFINITE);
302 CloseHandle(pi.hProcess);
303 CloseHandle(pi.hThread);
304 }
305
306 // Clean up error message utility afterwards.
307 DeleteFileA(exePath.c_str());
308}
309
310LONG WINAPI HandleException(EXCEPTION_POINTERS* exceptionInfo)
311{

Callers 2

HandleExceptionFunction · 0.85
WinMainFunction · 0.85

Calls 2

c_strMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected