943,148 Members | Top Members by Rank

Ad:
Jan 26th, 2010
0

Problem with GetAdaptersInfo

Expand Post »
I have a problem using the GetAdaptersInfo funtion on Delphi 2010 on Windows 7. The following code works fine and returns the adapter names/descriptions to the memo when compiled using Delphi 2007 on Windows Vista. When compiled using Delphi 2010 on Windows 7 it returns blanks or garbage (output below). Are there any compatibility problems using GetAdaptersInfo on Delphi 2010 or Windows 7? Heres some sample code that replicates the problem and the output for it, thanks for any help.

Code:

unit SDIMAIN;

interface

uses Windows, Classes, Graphics, Forms, Controls, Menus,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, ImgList, StdActns,
ActnList, ToolWin;

type
TSDIAppForm = class(TForm)
StatusBar: TStatusBar;
Button1: TButton;
Memo1: TMemo;

procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
SDIAppForm: TSDIAppForm;

implementation


uses about, IPHlpAPI, IPTypes, SysUtils;

{$R *.dfm}

procedure TSDIAppForm.Button1Click(Sender: TObject);
var
pAdapterInfo: PIP_ADAPTER_INFO;
AdapterInfo: IP_ADAPTER_INFO;
Status: DWORD;
BufLen: DWORD;
Buf: String;
I: integer;
begin
BufLen := sizeof(AdapterInfo);
pAdapterInfo := @AdapterInfo;
Status := GetAdaptersInfo(nil, BufLen);

pAdapterInfo := AllocMem(BufLen);

Status := GetAdaptersInfo(pAdapterInfo, BufLen);

while (pAdapterInfo <> nil) do
begin
Memo1.Lines.Add('Description: ' + pAdapterInfo^.Description);
Memo1.Lines.Add('Name: ' + pAdapterInfo^.AdapterName);
Buf := '';
for I := 0 to pAdapterInfo^.AddressLength - 1 do
Buf := Buf + '-' + IntToHex(pAdapterInfo^.Address[I], 2);
Delete(Buf, 1, 1);
Memo1.Lines.Add('MAC address: ' + Buf);
Memo1.Lines.Add('IP address: ' + pAdapterInfo^.IpAddressList.IpAddress.S);
Memo1.Lines.Add('Gateway: ' + pAdapterInfo^.GatewayList.IpAddress.S);
Memo1.Lines.Add('DHCP enabled: ' + IntTOStr(pAdapterInfo^.DhcpEnabled));
Memo1.Lines.Add('DHCP: ' + pAdapterInfo^.DhcpServer.IpAddress.S);
Memo1.Lines.Add('Have WINS: ' + BoolToStr(pAdapterInfo^.HaveWins));
Memo1.Lines.Add('Primary WINS: ' + pAdapterInfo^.PrimaryWinsServer.IpAddress.S);
Memo1.Lines.Add('Secondary WINS: ' + pAdapterInfo^.SecondaryWinsServer.IpAddress.S);
pAdapterInfo := pAdapterInfo^.Next;
end;
end;

end.

Memos output on Delphi 2007, Windows Vista:

Memo1
Description: D-Link DGE-530T Gigabit Ethernet Adapter (rev.B)
Name: {236E8044-8BE7-40B5-881A-D693F58A651D}
MAC address: 00-24-01-00-29-22
IP address: 0.0.0.0
Gateway: 0.0.0.0
DHCP enabled: 0
DHCP:
Have WINS: 0
Primary WINS:
Secondary WINS:
Description: Broadcom NetXtreme 57xx Gigabit Controller
Name: {C7D7F486-60E1-44A2-BD6B-7CEB92195A97}
MAC address: 00-19-B9-2E-D6-7D
IP address: 129.173.114.21
Gateway: 129.173.112.1
DHCP enabled: 1
DHCP: 129.173.1.100
Have WINS: 0
Primary WINS:
Secondary WINS:

Memos output on Delphi 2010, Windows 7:
Memo1
Description:
Name: 䑻㐹䕆䘵ⵁㄳ㕂㐭䅂ⴶ㍂䔰䈭㘴㘸㠹䐳䔶紶
MAC address:
IP address:
Gateway:
DHCP enabled: 0
DHCP:
Have WINS: 0
Primary WINS: 䲐뇥ꪗ
Secondary WINS: 㜱⸳㤱⸲1
Description: 㔲⸵㔲⸵㔲⸵㔲5궁搁
Name: 㕻㙅䐲ㄴⴸぃ㈶㐭㘰ⴱ㠹㐵䘭䈰㑃㝆䄱䉃組
MAC address:
IP address:
Gateway:
DHCP enabled: 0
DHCP:
Have WINS: 0
Primary WINS: ␀裡巻
Secondary WINS: ⸰0
Description:
Name: 㥻㘲䔱㐲ⵁ䅃䘸㐭㜳ⴵ㈹㤵㘭䐲䌲㉆䔲㘰組
MAC address:
IP address:
Gateway:
DHCP enabled: 0
DHCP:
Have WINS: 0
Primary WINS:
Secondary WINS:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bobsacamano is offline Offline
1 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Removing a symbol from a string
Next Thread in Pascal and Delphi Forum Timeline: Delphi 2007 Stored Procedure in SQL 2000





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC