function GetLastErrorMsg(IncludeErrorCode: Boolean): string;
var
ErrNo: Integer;
Buf: array[0..255] of Char;
begin
ErrNo := GetLastError;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, ErrNo, $400, Buf, 255, nil);
if Buf = '' then StrCopy(@Buf, PChar(SUnknowError));
Result := Buf;
if IncludeErrorCode then
Result := Result + #10#13 + SErrorCode + IntToStr(ErrNo);
end;