| 62 | } |
| 63 | |
| 64 | bool BWAPIError(const char *format, ...) |
| 65 | { |
| 66 | // Format the variable argument list |
| 67 | char buffer[MAX_PATH]; |
| 68 | va_list ap; |
| 69 | va_start(ap, format); |
| 70 | vsnprintf_s(buffer, MAX_PATH, MAX_PATH, format, ap); |
| 71 | va_end(ap); |
| 72 | |
| 73 | // Get the last error and error message |
| 74 | wchar_t szErrMsg[MAX_PATH]; |
| 75 | DWORD dwLastError = GetLastError(); |
| 76 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError, 0, szErrMsg, MAX_PATH, NULL); |
| 77 | |
| 78 | std::wostringstream errorMessage; |
| 79 | errorMessage << buffer << '\n' |
| 80 | << "ID " << reinterpret_cast<void*>(dwLastError) << ": \n" |
| 81 | << szErrMsg << std::endl; |
| 82 | |
| 83 | // Open a log file and print to it |
| 84 | std::wofstream log{ "bwapi-error.txt", std::ios::app }; |
| 85 | if (log) |
| 86 | { |
| 87 | const time_t now = std::time(nullptr); |
| 88 | log << '[' << std::put_time(std::localtime(&now), L"%F %T") << "] " << errorMessage.str(); |
| 89 | } |
| 90 | |
| 91 | // Create a message box with the message and the error message |
| 92 | MessageBox(NULL, errorMessage.str().c_str(), NULL, MB_OK | MB_ICONERROR); |
| 93 | return false; |
| 94 | } |
no test coverage detected