except: explicitly qualify win32 message table

if the mesage table isn't specified when formatting error codes some
systems will fail to render the string.
This commit is contained in:
Danny Robson 2016-04-15 15:55:30 +10:00
parent fa8933673f
commit 755ba5a6a7

View File

@ -18,6 +18,7 @@
#include "./debug.hpp" #include "./debug.hpp"
#include "./platform.hpp" #include "./platform.hpp"
#include "./cast.hpp" #include "./cast.hpp"
#include "./types.hpp"
#include <cstring> #include <cstring>
#include <cerrno> #include <cerrno>
@ -147,16 +148,27 @@ win32_error::code_string (void)
return code_string (GetLastError ()); return code_string (GetLastError ());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string std::string
win32_error::code_string (DWORD code) win32_error::code_string (DWORD code)
{ {
char message[256]; char message[256];
auto res = FormatMessage (0, NULL, code, 0, message, sizeof (message), NULL); auto res = FormatMessage (
if (res == 0) FORMAT_MESSAGE_FROM_SYSTEM,
win32_error::throw_code (); NULL,
code,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
message,
elems (message),
NULL
);
return std::string (message); if (res == 0) {
win32_error::throw_code ();
}
return std::string (message, message + res);
} }
#endif #endif