Article View: borland.public.cppbuilder.nativeapi
Article #1912Help on an Undocumented call
From: Colin B Maharaj
Date: Mon, 04 Jun 2007 17:42
Date: Mon, 04 Jun 2007 17:42
62 lines
2445 bytes
2445 bytes
Hi all,
I was trying to write an interface to change an IP Address on a PC
programatically. I used netsh and tested it in WinXP and it was OK
The person who I wrote it for said it was not working in his environment
which was 2000. I then did some serious digging and got the undocumented
ip helper function called
SetAdapterIpAddress
which function I prototyped as ...
#include "iphlpapi.h"
typedef DWORD (WINAPI *PSETADAPTERIPADDRESS)(
const char*,DWORD,DWORD,DWORD,DWORD
);
declared as...
PSETADAPTERIPADDRESS SetAdapterIpAddress;
and got a function address like......
hLib = LoadLibrary("Iphlpapi.dll");
SetAdapterIpAddress =
(PSETADAPTERIPADDRESS)GetProcAddress(hLib,"SetAdapterIpAddress");
And use like this....
//-------------------------------------------------------------------------------------
#include "iphlpapi.h"
bool ChangeAdaptorAddress(AnsiString A, AnsiString B, AnsiString C)
{
IPAddr A1, B1, C1;
A1 = inet_addr(A.c_str());
B1 = inet_addr(B.c_str());
C1 = inet_addr(C.c_str());
int retvalue = SetAdapterIpAddress(card.c_str(), 0, A1, B1, C1);
// ShowMessage(retvalue );
}
In my environment, retvalue return 0
in the 2000 environment it returns 2
card is the uuid address taken from the registry.
0
mean no DHCP.
I know this is a toughy and no guarantees for help
but I need to set the address without restarting the PC
If anyone has an Idea how to get this working
let me know.
(2 - is like 'File Not found' or something)
Technical Details
Message-ID:
<46644efb@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,838f5bf7bf191071,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 04 Jun 2007 13:42:18 -0400 From: Colin B Maharaj <noreply@myhost.com> User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Help on an Undocumented call Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 000747-0, 06/04/2007), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 201.238.97.177 Message-ID: <46644efb@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1180978939 201.238.97.177 (4 Jun 2007 10:42:19 -0700) Lines: 65 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail