diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-24 01:34:52 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-24 02:06:22 +0300 |
commit | c073ed8f702e98ec56ed05e0c02167e355e6ee31 (patch) | |
tree | f726a5830ed4f47724ac6c447571398ef5b12ea2 /src/error.cpp | |
parent | add Process class (diff) | |
download | winapi-debug-c073ed8f702e98ec56ed05e0c02167e355e6ee31.tar.gz winapi-debug-c073ed8f702e98ec56ed05e0c02167e355e6ee31.zip |
switch to Boost.Nowide everywhere
Diffstat (limited to '')
-rw-r--r-- | src/error.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/error.cpp b/src/error.cpp index 16512b3..d305e88 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -5,6 +5,8 @@ #include "pdb/all.hpp" +#include <boost/nowide/convert.hpp> + #include <windows.h> #include <string> @@ -13,9 +15,9 @@ namespace pdb { namespace error { namespace { -std::string trim_trailing_newline(const std::string& s) { - const auto last_pos = s.find_last_not_of("\r\n"); - if (std::string::npos == last_pos) +std::wstring trim_trailing_newline(const std::wstring& s) { + const auto last_pos = s.find_last_not_of(L"\r\n"); + if (std::wstring::npos == last_pos) return {}; return s.substr(0, last_pos + 1); } @@ -23,25 +25,25 @@ std::string trim_trailing_newline(const std::string& s) { } // namespace std::string CategoryWindows::message(int code) const { - char* buf; + wchar_t* buf; - const auto nbwritten = FormatMessageA( + const auto len = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast<char*>(&buf), + reinterpret_cast<wchar_t*>(&buf), 0, NULL); - if (0 == nbwritten) { + if (0 == len) { LocalFree(buf); return "Couldn't format the error message"; } - std::string msg{buf, nbwritten}; + std::wstring msg{buf, len}; LocalFree(buf); - return trim_trailing_newline(msg); + return boost::nowide::narrow(trim_trailing_newline(msg)); } } // namespace error |