Article View: borland.public.cppbuilder.nativeapi
Article #11927GetAdaptersInfo problem
From: Baz
Date: Wed, 07 Jan 2004 12:08
Date: Wed, 07 Jan 2004 12:08
46 lines
2286 bytes
2286 bytes
Hi All,
Found some code on the msdn site for finding all network adapters on a
machine using the GetAdaptersInfo.
Works fine for reading theinformation but causes the application crash on
exit...
Any idea what im missing???
code as below:
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
pAdapterInfo = (IP_ADAPTER_INFO *) malloc ( sizeof(IP_ADAPTER_INFO) );
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) !=
ERROR_BUFFER_OVERFLOW )
{
free( pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc ( sizeof(ulOutBufLen));
}
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == NO_ERROR)
{
pAdapter = pAdapterInfo;
while (pAdapter != NULL)
{
// Add new item to list.
TListItem *newitem;
newitem = lsvAdapters->Items->Add();
// Get the Adapter Name.
newitem->Caption = (char*)pAdapter->Description;
// Add the IP Address.
String temp = pAdapter->IpAddressList.IpAddress.String;
newitem->SubItems->Add(temp);
}
}
else
ShowMessage("Call to GetAdaptersInfo failed.");
// free( pAdapterInfo);
Technical Details
Message-ID:
<3ffbf6b6$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,d754bc29b79fd8f7,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-07 04:09:38 PST Reply-To: "Baz" <.@.com> From: "Baz" <.@.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: GetAdaptersInfo problem Date: Wed, 7 Jan 2004 12:08:20 -0000 Lines: 48 Organization: .@.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 217.44.82.26 Message-ID: <3ffbf6b6$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073477302 217.44.82.26 (7 Jan 2004 04:08:22 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail