fix: Native error message formatting on Windows

This commit is contained in:
WerWolv
2024-02-04 20:21:16 +01:00
parent f583df6c7d
commit 77baf6f522
4 changed files with 95 additions and 83 deletions

View File

@@ -4,6 +4,7 @@
#include <hex/helpers/logger.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/auto_reset.hpp>
#include <hex/helpers/utils.hpp>
#include <wolv/utils/string.hpp>
@@ -24,7 +25,7 @@ namespace hex {
m_handle = uintptr_t(LoadLibraryW(path.c_str()));
if (m_handle == uintptr_t(INVALID_HANDLE_VALUE) || m_handle == 0) {
log::error("Loading plugin '{}' failed: {} {}!", wolv::util::toUTF8String(path.filename()), ::GetLastError(), std::system_category().message(::GetLastError()));
log::error("Loading plugin '{}' failed: {} {}!", wolv::util::toUTF8String(path.filename()), ::GetLastError(), hex::formatSystemError(::GetLastError()));
return;
}
#else
@@ -91,7 +92,7 @@ namespace hex {
#if defined(OS_WINDOWS)
if (m_handle != 0)
if (FreeLibrary(HMODULE(m_handle)) == FALSE) {
log::error("Error when unloading plugin '{}': {}!", wolv::util::toUTF8String(m_path.filename()), std::system_category().message(::GetLastError()));
log::error("Error when unloading plugin '{}': {}!", wolv::util::toUTF8String(m_path.filename()), hex::formatSystemError(::GetLastError()));
}
#else
if (m_handle != 0)

View File

@@ -750,4 +750,14 @@ namespace hex {
return generateHexViewImpl(offset, data.begin(), data.end());
}
std::string formatSystemError(i32 error) {
auto message = std::system_category().message(error);
#if defined(OS_WINDOWS)
return hex::utf16ToUtf8(hex::utf8ToUtf16(message));
#else
return message;
#endif
}
}