mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-28 11:20:53 +00:00
Changed: Return error message as an UTF-8 string
This commit is contained in:
parent
c9411e43c5
commit
486282262e
1 changed files with 10 additions and 5 deletions
|
@ -1429,22 +1429,27 @@ int getLastError()
|
||||||
std::string formatErrorMessage(int errorCode)
|
std::string formatErrorMessage(int errorCode)
|
||||||
{
|
{
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
LPVOID lpMsgBuf;
|
LPVOID lpMsgBuf = NULL;
|
||||||
FormatMessage(
|
DWORD len = FormatMessageW(
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL,
|
NULL,
|
||||||
errorCode,
|
errorCode,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
||||||
(LPTSTR) &lpMsgBuf,
|
(LPWSTR) &lpMsgBuf,
|
||||||
0,
|
0,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
string ret = (char*)lpMsgBuf;
|
// empty buffer, an error occured
|
||||||
|
if (len == 0) return toString("FormatMessage returned error %d", getLastError());
|
||||||
|
|
||||||
|
// convert wchar_t* to std::string
|
||||||
|
string ret = wideToUtf8(lpMsgBuf);
|
||||||
|
|
||||||
// Free the buffer.
|
// Free the buffer.
|
||||||
LocalFree( lpMsgBuf );
|
LocalFree(lpMsgBuf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue