diff options
author | Max Kellermann <max@musicpd.org> | 2021-03-08 22:53:59 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2021-03-08 22:54:46 +0100 |
commit | 24a205a1aa80318c72ffd9d2a84b05b88845cb3a (patch) | |
tree | 888b4f0f06ed9a5f9c7c98ef7c77093809b70a3a /src | |
parent | 3a948515ceccd0d2da44f5aad567d76a665e3d1a (diff) |
win32/HResult: try to use FormatMessage()
Diffstat (limited to 'src')
-rw-r--r-- | src/win32/HResult.cxx | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/win32/HResult.cxx b/src/win32/HResult.cxx index a40116a1b..0daa80163 100644 --- a/src/win32/HResult.cxx +++ b/src/win32/HResult.cxx @@ -18,6 +18,7 @@ */ #include "HResult.hxx" +#include "system/Error.hxx" #include <cassert> #include <cstdarg> @@ -27,11 +28,21 @@ std::string HResultCategory::message(int Errcode) const { + char buffer[256]; + + /* FormatMessage() supports some HRESULT values (depending on + the Windows version) */ + if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, Errcode, 0, + buffer, sizeof(buffer), + nullptr)) + return buffer; + const auto msg = HRESULTToString(Errcode); if (!msg.empty()) return std::string(msg); - char buffer[11]; // "0x12345678\0" int size = snprintf(buffer, sizeof(buffer), "0x%1x", Errcode); assert(2 <= size && size <= 10); return std::string(buffer, size); |