2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 09:56:22 +01:00

engine: platform: win32: request error string in wide chars and then transform it to UTF-8 using our utflib

This commit is contained in:
Alibek Omarov 2024-07-09 08:24:58 +03:00
parent 166bed732e
commit a1191eb4ab

View File

@ -296,15 +296,17 @@ table_error:
static const char *GetLastErrorAsString( void )
{
const DWORD fm_flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK;
DWORD errorcode;
wchar_t wide_errormessage[256];
static string errormessage;
errorcode = GetLastError();
if ( !errorcode ) return "";
if ( !errorcode )
return "";
FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, errorcode, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
(LPSTR)&errormessage, sizeof( errormessage ), NULL );
FormatMessageW( fm_flags, NULL, errorcode, 0, wide_errormessage, ARRAYSIZE( wide_errormessage ), NULL );
Q_UTF16ToUTF8( errormessage, sizeof( errormessage ), wide_errormessage, ARRAYSIZE( wide_errormessage ));
return errormessage;
}