From 486282262e563710dec12c730b5e70d6e737ab2f Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 21 Oct 2016 12:55:02 +0200 Subject: [PATCH] Changed: Return error message as an UTF-8 string --- code/nel/src/misc/debug.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index 1f0bb4fd1..c9ac2f593 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -1429,22 +1429,27 @@ 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 ); + LocalFree(lpMsgBuf); return ret; #else