* use FormatMessageW in SysErrorMessage, resolves issue #29197

git-svn-id: trunk@32835 -
This commit is contained in:
florian 2016-01-03 15:56:31 +00:00
parent 77229a3cdf
commit d4d4689914

View File

@ -944,16 +944,16 @@ function SysErrorMessage(ErrorCode: Integer): String;
const const
MaxMsgSize = Format_Message_Max_Width_Mask; MaxMsgSize = Format_Message_Max_Width_Mask;
var var
MsgBuffer: pChar; MsgBuffer: PUnicodeChar;
begin begin
GetMem(MsgBuffer, MaxMsgSize); GetMem(MsgBuffer, MaxMsgSize*2);
FillChar(MsgBuffer^, MaxMsgSize, #0); FillChar(MsgBuffer^, MaxMsgSize*2, #0);
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
nil, nil,
ErrorCode, ErrorCode,
MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT), MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
MsgBuffer, { This function allocs the memory } MsgBuffer,
MaxMsgSize, { Maximum message size } MaxMsgSize,
nil); nil);
SysErrorMessage := MsgBuffer; SysErrorMessage := MsgBuffer;
FreeMem(MsgBuffer, MaxMsgSize); FreeMem(MsgBuffer, MaxMsgSize);