Hallo zusammen,
ich würde gerne die Struktur von
IP_ADAPTER_ADDRESSES nach Delphi übersetzen. Es funktioniert auch soweit, nur das er bei den Werten die als PWCHAR deklariert sind, garnichts oder etwas falsches rausbringt.
Delphi-Quellcode:
type
PIP_ADAPTER_ADDRESSES = ^IP_ADAPTER_ADDRESSES;
IP_ADAPTER_ADDRESSES = record
Union: record
case Integer of
0: (Alignment: LongInt);
1: (Length: LongInt; IfIndex: DWORD);
end;
Next : PIP_ADAPTER_ADDRESSES;
AdapterName : PCHAR;
DnsSuffix : PWCHAR;
Description : PWCHAR;
FriendlyName : PWCHAR;
PhysicalAddress : array [0..MAX_ADAPTER_ADDRESS_LENGTH - 1] of BYTE;
PhysicalAddressLength : DWORD;
Flags : DWORD;
Mtu : DWORD;
IfType : DWORD;
Ipv6IfIndex : DWORD;
ZoneIndices : array [0..15] of DWORD;
TransmitLinkSpeed : Int64;
ReceiveLinkSpeed : Int64;
Ipv4Metric : LongInt;
Ipv6Metric : LongInt;
end;
PVOID = Pointer;
function GetAdaptersAddresses(Family: ULONG; Flags: DWORD; Reserved: PVOID;
pAdapterAddresses: PIP_ADAPTER_ADDRESSES; pOutBufLen: PULONG): DWORD; stdcall;
external 'IPHLPAPI.DLL' name 'GetAdaptersAddresses';
Delphi-Quellcode:
var
adapter:pip_adapter_addresses;
buffer:dword;
Error:dword;
begin
error := GetAdaptersAddresses(0, 0, nil, nil, @buffer);
if error <> ERROR_BUFFER_OVERFLOW then
ShowMessage('Not enough memory');
adapter := AllocMem(buffer);
error := GetAdaptersAddresses(0, 0, nil, adapter, @buffer);
if error = ERROR_SUCCESS then
begin
case adapter.IfType of
IF_TYPE_ETHERNET_CSMACD : Label13.Caption := 'Adapter Type : Ethernet';
IF_TYPE_SOFTWARE_LOOPBACK : Label13.Caption := 'Adapter Type : Loopback';
IF_TYPE_TUNNEL : Label13.Caption := 'Adapter Type : Tunnel';
IF_TYPE_IEEE1394 : Label13.Caption := 'Adapter Type : FireWire 1394';
end;
Label14.Caption := 'Name : ' + WideCharToString(adapter.FriendlyName);
Label15.Caption := 'Transmit Link Speed : ' + IntToStr(adapter.TransmitLinkSpeed);
Label16.Caption := 'Recieve Link Speed : ' + IntToStr(adapter.ReceiveLinkSpeed);
end
else
ShowMessage( SysErrorMessage( Error ) );
FreeMem(adapter, buffer);
end;
Habe ich da wieder irgendwas durcheinander gebracht oder liegt es an meinem Aufruf ?