| 70 | } |
| 71 | |
| 72 | static LONG WINAPI ExceptionHandler(__in struct _EXCEPTION_POINTERS *ep) |
| 73 | { |
| 74 | static BOOL HasDumped = FALSE; |
| 75 | |
| 76 | CStringW MinidumpFile; |
| 77 | int dump_counter = 0; |
| 78 | |
| 79 | // Prevent multiple calls to this exception handler |
| 80 | if (HasDumped == TRUE) |
| 81 | ExitProcess(0); |
| 82 | |
| 83 | HasDumped = TRUE; |
| 84 | |
| 85 | MinidumpFile = GetDumpFilename(dump_counter++); |
| 86 | |
| 87 | while (GetFileAttributesW(MinidumpFile) != 0xFFFFFFFF) |
| 88 | MinidumpFile = GetDumpFilename(dump_counter++); |
| 89 | |
| 90 | HANDLE hFile = CreateFileW(MinidumpFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 91 | |
| 92 | // Save the memory dump file |
| 93 | if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) { |
| 94 | // Create the minidump |
| 95 | MINIDUMP_EXCEPTION_INFORMATION mdei; |
| 96 | mdei.ThreadId = GetCurrentThreadId(); |
| 97 | mdei.ExceptionPointers = ep; |
| 98 | mdei.ClientPointers = FALSE; |
| 99 | |
| 100 | HANDLE hProcess = GetCurrentProcess(); |
| 101 | DWORD dwProcessId = GetCurrentProcessId(); |
| 102 | |
| 103 | MiniDumpWriteDump(hProcess, dwProcessId, hFile, MiniDumpNormal, (ep != 0) ? &mdei : NULL, 0, 0); |
| 104 | |
| 105 | CloseHandle(hFile); |
| 106 | } |
| 107 | |
| 108 | // Find a free filename. |
| 109 | // Start with "recover" and append a number if file exists. |
| 110 | CStringW DocDumpFile = FTM_DUMP; |
| 111 | int counter = 1; |
| 112 | |
| 113 | while (GetFileAttributesW(DocDumpFile + L".ftm") != 0xFFFFFFFF) |
| 114 | DocDumpFile = FormattedW(L"%s%i", FTM_DUMP, counter++); |
| 115 | |
| 116 | DocDumpFile.Append(L".ftm"); |
| 117 | |
| 118 | // Display a message |
| 119 | CStringW text = L"This application has encountered a problem and needs to close.\n\n"; |
| 120 | if (ep->ExceptionRecord->ExceptionCode == 0xE06D7363) { // // // |
| 121 | auto wmsg = conv::to_wide(reinterpret_cast<const std::exception *>(ep->ExceptionRecord->ExceptionInformation[1])->what()); |
| 122 | AppendFormatW(text, L"Unhandled C++ exception:\" %.*s\".\n\n", wmsg.size(), wmsg.data()); |
| 123 | } |
| 124 | else |
| 125 | AppendFormatW(text, L"Unhandled exception %X.\n\n", ep->ExceptionRecord->ExceptionCode); |
| 126 | AppendFormatW(text, L"A memory dump file has been created (%s), please include this if you file a bug report!\n\n", LPCWSTR(MinidumpFile)); |
| 127 | AppendFormatW(text, L"Attempting to save current module as %s.", LPCWSTR(DocDumpFile)); |
| 128 | // text.Append(L"Application will now close."); |
| 129 | AfxMessageBox(text, MB_ICONSTOP); |
nothing calls this directly
no test coverage detected