Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by Colin B Maharaj
Mon, 04 Jun 2007 17:42
Help on an Undocumented call
Author: 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)
Re: Help on an Undocumented call
Author: Ed Mulroy
Date: Mon, 04 Jun 2007 18:30
Date: Mon, 04 Jun 2007 18:30
71 lines
2977 bytes
2977 bytes
Maybe this will help. It's written for VB but with a little work you should
be able to translate it to something understandable
http://tinyurl.com/ytabvg
AKA
http://www.msfn.org/board/lofiversion/index.php/t70524.html
. Ed
> Colin B Maharaj wrote in message
> news:46644efb@newsgroups.borland.com...
> 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)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads