| 264 | } |
| 265 | |
| 266 | void 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 | |
| 310 | LONG WINAPI HandleException(EXCEPTION_POINTERS* exceptionInfo) |
| 311 | { |
no test coverage detected