Q: How can I change the static IP assigned to my development system at run-time?
To change a static IP address you must do two things:
- Change the adapter's registry settings
You must change the following keys:- EnableDHCP
- IpAddress
- DNS
- DefaultGateway
- Subnetmask
As an example, the keys for the on-board adapter for ADS devices would be in the following location: HKEY_LOCAL_MACHINE\Comm\SMC90001\Parms\TcpIp
- Rebind the adapter through code
The following code shows how to rebind the on-board adapters for ADS devices.
#include
#define FILE_ANY_ACCESS 0 #define METHOD_OUT_DIRECT 2 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017 #define WINCE_IOCTL_START 8 #define DD_NDIS_DEVICE_NAME TEXT("NDS0:")
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \ ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) )
#define _NDIS_CONTROL_CODE(request,method) CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, method, FILE_ANY_ACCESS) #define IOCTL_NDIS_REBIND_ADAPTER (_NDIS_CONTROL_CODE( WINCE_IOCTL_START+3, METHOD_OUT_DIRECT ))
#define ADAPTER_NAME _T("SMC90001")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, LPWSTR pszCmdLine, int nCmdShow) { // open the NDIS driver HANDLE hNdis = ::CreateFile(DD_NDIS_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
// rebind out adapter DeviceIoControl(hNdis, IOCTL_NDIS_REBIND_ADAPTER, ADAPTER_NAME, _tcslen(ADAPTER_NAME) + 1, NULL, NULL, NULL, NULL);
// close the driver CloseHandle (hNdis);
return 0; }
|