mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-06 22:07:56 +02:00
* Remove trailing #13#10 in the result of SysErrorMessage() on Windows and minor optimization. It is Delphi compatible.
git-svn-id: trunk@34220 -
This commit is contained in:
parent
980c4741ac
commit
e3ebaa6e6a
@ -978,19 +978,22 @@ function SysErrorMessage(ErrorCode: Integer): String;
|
||||
const
|
||||
MaxMsgSize = Format_Message_Max_Width_Mask;
|
||||
var
|
||||
MsgBuffer: PUnicodeChar;
|
||||
MsgBuffer: unicodestring;
|
||||
len: longint;
|
||||
begin
|
||||
GetMem(MsgBuffer, MaxMsgSize*2);
|
||||
FillChar(MsgBuffer^, MaxMsgSize*2, #0);
|
||||
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
nil,
|
||||
ErrorCode,
|
||||
MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
MsgBuffer,
|
||||
MaxMsgSize,
|
||||
nil);
|
||||
SysErrorMessage := MsgBuffer;
|
||||
FreeMem(MsgBuffer, MaxMsgSize*2);
|
||||
SetLength(MsgBuffer, MaxMsgSize);
|
||||
len := FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
nil,
|
||||
ErrorCode,
|
||||
MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
PUnicodeChar(MsgBuffer),
|
||||
MaxMsgSize,
|
||||
nil);
|
||||
// Remove trailing #13#10
|
||||
if (len > 1) and (MsgBuffer[len - 1] = #13) and (MsgBuffer[len] = #10) then
|
||||
Dec(len, 2);
|
||||
SetLength(MsgBuffer, len);
|
||||
Result := MsgBuffer;
|
||||
end;
|
||||
|
||||
{****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user