function SysErrorMessage(ErrorCode: DWORD):
string;
var
Len : Integer;
Buffer :
array[0..2048]
of Char;
hDll : THandle;
resourcestring
rsErrMsg = '
Fehlercode nicht gefunden';
begin
SetLength(Result, 2048-16);
Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
nil, ErrorCode, 0, Buffer, SizeOf(Buffer),
nil);
if Len = 0
then
begin
hDll := LoadLibraryEx('
netmsg.dll', 0, DONT_RESOLVE_DLL_REFERENCES);
if hDll <> 0
then
begin
Len := FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
or FORMAT_MESSAGE_FROM_SYSTEM, Pointer(hDll), ErrorCode, 0, Buffer,
sizeof(Buffer),
nil);
FreeLibrary(hDll);
if Len <> 0
then
begin
while (Len > 0)
and (Buffer[Len - 1]
in [#0..#32, '
.'])
do
Dec(Len);
SetString(Result, Buffer, Len);
end
else
result := rsErrMsg;
end;
end
else
begin
while (Len > 0)
and (Buffer[Len - 1]
in [#0..#32, '
.'])
do
Dec(Len);
SetString(Result, Buffer, Len);
end;
end;