mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-20 09:49:08 +02:00
win32: SysErrorMessage: ignore inserts (when not used the messages with inserts are empty) and allocate message buffer
git-svn-id: trunk@47748 -
This commit is contained in:
parent
1efeb5851a
commit
6eb37beb24
@ -1317,25 +1317,26 @@ end;
|
|||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
|
||||||
function SysErrorMessage(ErrorCode: Integer): String;
|
function SysErrorMessage(ErrorCode: Integer): String;
|
||||||
const
|
|
||||||
MaxMsgSize = Format_Message_Max_Width_Mask;
|
|
||||||
var
|
var
|
||||||
MsgBuffer: unicodestring;
|
MsgBuffer: PWideChar;
|
||||||
|
Msg: UnicodeString;
|
||||||
len: longint;
|
len: longint;
|
||||||
begin
|
begin
|
||||||
SetLength(MsgBuffer, MaxMsgSize);
|
len := FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM or
|
||||||
len := FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
|
FORMAT_MESSAGE_IGNORE_INSERTS or
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||||
nil,
|
nil,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
PUnicodeChar(MsgBuffer),
|
PWideChar(@MsgBuffer),
|
||||||
MaxMsgSize,
|
0,
|
||||||
nil);
|
nil);
|
||||||
// Remove trailing #13#10
|
// Remove trailing #13#10
|
||||||
if (len > 1) and (MsgBuffer[len - 1] = #13) and (MsgBuffer[len] = #10) then
|
if (len > 1) and (MsgBuffer[len - 2] = #13) and (MsgBuffer[len - 1] = #10) then
|
||||||
Dec(len, 2);
|
Dec(len, 2);
|
||||||
SetLength(MsgBuffer, len);
|
SetString(Msg, PUnicodeChar(MsgBuffer), len);
|
||||||
Result := MsgBuffer;
|
LocalFree(HLOCAL(MsgBuffer));
|
||||||
|
Result := Msg;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user