| 12 | #include <windows.h> |
| 13 | |
| 14 | std::string windows_format_system_message(unsigned long error) |
| 15 | { |
| 16 | WCHAR *wide_message; |
| 17 | const DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_MAX_WIDTH_MASK; |
| 18 | if(FormatMessageW(flags, nullptr, error, 0, (LPWSTR)&wide_message, 0, nullptr) == 0) |
| 19 | return "unknown error"; |
| 20 | |
| 21 | std::optional<std::string> message = windows_wide_to_utf8(wide_message); |
| 22 | LocalFree(wide_message); |
| 23 | return message.value_or("(invalid UTF-16 in error message)"); |
| 24 | } |
| 25 | |
| 26 | std::wstring windows_args_to_wide(const char **arguments, size_t num_arguments) |
| 27 | { |
no test coverage detected