Changed: Return error message as an UTF-8 string
This commit is contained in:
parent
88a87a07a0
commit
2583d447f3
1 changed files with 10 additions and 5 deletions
|
@ -1429,20 +1429,25 @@ int getLastError()
|
|||
std::string formatErrorMessage(int errorCode)
|
||||
{
|
||||
#ifdef NL_OS_WINDOWS
|
||||
LPVOID lpMsgBuf;
|
||||
FormatMessage(
|
||||
LPVOID lpMsgBuf = NULL;
|
||||
DWORD len = FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
errorCode,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
(LPWSTR) &lpMsgBuf,
|
||||
0,
|
||||
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.
|
||||
LocalFree(lpMsgBuf);
|
||||
|
||||
|
|
Loading…
Reference in a new issue