type
TGetAdapterAdresses =
function(Family: ULONG; Flags: cardinal;
Reserved: PVOID; pAdapterAddresses: PIP_ADAPTER_ADDRESSES;
pOutBufLen: PULONG) : DWORD;
stdcall;
function SafeLoadLibrary(
const Filename:
String; ErrorMode: UINT): HMODULE;
var
SaveErrorMode: UINT;
SaveFPUControlWord: Word;
begin
SaveErrorMode := SetErrorMode(ErrorMode);
try
asm FNSTCW SaveFPUControlWord
end;
try
Result := LoadLibrary(PChar(Filename));
finally
asm
FNCLEX
FLDCW SaveFPUControlWord
end;
end;
finally
SetErrorMode(SaveErrorMode);
end;
end;
function GetAdapterAdresses(Family: ULONG; Flags: cardinal; Reserved: PVOID;
pAdapterAddresses: PIP_ADAPTER_ADDRESSES; pOutBufLen: PULONG) : DWORD;
var
DLLProc: TGetAdapterAdresses;
DLLHandle: THandle;
begin
result := 0;
try
DLLHandle := SafeLoadLibrary('
IPHLPAPI.DLL', SEM_NOOPENFILEERRORBOX);
if DLLHandle <> 0
then begin
try
@DLLProc := GetProcAddress(DLLHandle, '
GetAdapterAdresses');
if @DLLProc <>
nil
result := DLLProc(Family, Flags, Reserved, pAdapterAddresses, pOutBufLen);
finally
FreeLibrary(DLLHandle);
end;
end;
except
result := DWORD(-1);
end;
end;