Article View: borland.public.cppbuilder.nativeapi
Article #11514Re: getadaptersinfo....
From: Ed Mulroy [TeamB]
Date: Fri, 06 Feb 2004 15:38
Date: Fri, 06 Feb 2004 15:38
82 lines
2991 bytes
2991 bytes
If you look at the docs on that function one of the reasons for the invalid
parameter return value is for the situation where you do not own the memory
at the address given. By convention your program does not own the NULL
address, it is an invalid addres, so the error makes sense. Put the address
of something in there. Here is an example I ran just to illustrate:
------------------
C:\Documents and Settings\Administrator\My Documents\Lookat\Temp
>type temp5.cpp
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
const char *GetReason(DWORD val)
{
char *msg;
switch (val)
{
case ERROR_BUFFER_OVERFLOW :
msg = "ERROR_BUFFER_OVERFLOW";
break;
case ERROR_INVALID_PARAMETER :
msg = "ERROR_INVALID_PARAMETER";
break;
default :
msg = "Other message";
break;
}
return msg;
}
int main()
{
unsigned long ulAdapterSize=0;
DWORD result = GetAdaptersInfo(NULL, &ulAdapterSize);
printf("NULL gives %s\n", GetReason(result));
char c;
result = GetAdaptersInfo((PIP_ADAPTER_INFO) &c, &ulAdapterSize);
printf("&char gives %s\n", GetReason(result));
return 0;
}
C:\Documents and Settings\Administrator\My Documents\Lookat\Temp
>ver
Microsoft Windows XP [Version 5.1.2600]
C:\Documents and Settings\Administrator\My Documents\Lookat\Temp
>temp5
NULL gives ERROR_BUFFER_OVERFLOW
&char gives ERROR_INVALID_PARAMETER
C:\Documents and Settings\Administrator\My Documents\Lookat\Temp
>
------------------
. Ed
> derek wrote in message
> news:40237638$1@newsgroups.borland.com...
>
> Does any one know why the call to GetAdaptersInfo returns:
>
> ERROR_BUFFER_OVERFLOW on my Win2k machine...but
> ERROR_INVALID_PARAMETER on an XP machine?
>
> I'm using CB5 pro on both machines.
>
> ULONG ulAdapterSize=0;
>
> if(GetAdaptersInfo(NULL, &ulAdapterSize) ==
> ERROR_BUFFER_OVERFLOW)
> {
> <--SNIP-->
Technical Details
Message-ID:
<4023b4e7$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-mailReferences:
<40237638$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ce3424bce4f1c00e X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-02-06 07:40:30 PST From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <40237638$1@newsgroups.borland.com> Subject: Re: getadaptersinfo.... Date: Fri, 6 Feb 2004 10:38:14 -0500 Lines: 84 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.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <4023b4e7$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1076081895 24.74.175.102 (6 Feb 2004 07:38:15 -0800) X-Authenticated-User: edmulroy 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