Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I assign an ip form within a program on Windows CE 6.0

409 views
Skip to first unread message

Don

unread,
May 31, 2010, 4:17:01 PM5/31/10
to

Hi

I know in Windows CE 6.0 you can change the ip address on the device by
doing the following

1. Navigate to : Start -> Settings -> Control Panel -> Network and
Dial up Connections
2. Right click on the network adapter and select Properties
3. You will see the IP Settings dialog box
4. Click Specify an IP address and fill it in

I would like to do the same thing in a program. What do I wirte too? Are
they registry entries or something in the smbserver.dll? Can someone please
provide some detail on what to write too?

--
Don

KMOS

unread,
May 31, 2010, 4:47:38 PM5/31/10
to
Just trace the source code of network applet of Control Panel.
You could start from the following code

showProperties in public\common\oak\drivers\netsamp\connmc\LanConnInfo.cpp
AdapterIPProperties in public\common\oak\drivers\netui\network.c

"Don" <D...@discussions.microsoft.com> wrote in message
news:B49AE3D8-631F-45CE...@microsoft.com...

Vinoth [MCTS]

unread,
Jun 1, 2010, 3:08:01 AM6/1/10
to

i have given a sample code to change the adapter IP addresses. have a look.
Hope it will help you. i did it for SMSC9118 adapter. same thing you can do
it for your adapter. All the adapters are listed in [HKEY_LOCAL_MACHINE\Comm\
registry.


/**********************************************************************
[HKEY_LOCAL_MACHINE\Comm\SMSC91181\Parms\TcpIp]
"EnableDHCP"=dword:0
"IpAddress"="192.168.0.239"
"Subnetmask"="255.255.255.0"
"DefaultGateway"="192.168.0.1"
"UseZeroBroadcast"=dword:0
"DNS"="202.56.230.5"
**********************************************************************/


// SetAdaptorInfo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <Iphlpapi.h>
#include "Winsock2.h"
#define IOCTL_NDIS_REBIND_ADAPTER 0x17002e

//IP_ADAPTER_INFO AdapterInfo[4];
typedef struct _ADDRESS_NETWORK
{
TCHAR IP[16];
TCHAR GW[16];
TCHAR SNM[16];

}ADDRESS_NETWORK;

ADDRESS_NETWORK gAddress;


//This will set the Ip address, Gateway address and SubnetMask Address
void SetNetworkRegistry(void)
{
TCHAR szTemp[256];
HKEY hKey;
LONG hRes;
DWORD xcount;
//Copy the Sub Registry key name in to the string

_tcscpy (szTemp, TEXT("Comm\\SMSC91181\\Parms\\TcpIp"));

wcscpy(gAddress.IP,L"192.168.0.118");
wcscpy(gAddress.GW,L"192.168.0.1");
wcscpy(gAddress.SNM,L"255.255.255.0");
hKey = NULL;
//Open the registry Key
hRes = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szTemp, 0, 0, &hKey);
if (ERROR_SUCCESS == hRes && hKey != NULL)
{
// Set the IP Address Registry Setting
if(!(RegSetValueEx (hKey, TEXT("IpAddress"), 0, REG_MULTI_SZ, (const
UINT8*)gAddress.IP, sizeof(gAddress.IP)) == ERROR_SUCCESS ))
{
wprintf(L"ERROR IN IpAddress OPEN\r\n");
}

// Set the Subnet Mask Address Registry Setting
if(!(RegSetValueEx (hKey, TEXT("Subnetmask"), 0, REG_MULTI_SZ, (const
UINT8*)gAddress.SNM, sizeof(gAddress.SNM)) == ERROR_SUCCESS ))
{
wprintf(L"ERROR IN Subnetmask OPEN\r\n");
}

// Set the gateway Address Registry Setting
if(!(RegSetValueEx (hKey, TEXT("DefaultGateway"), 0, REG_MULTI_SZ, (const
UINT8*)gAddress.GW, sizeof(gAddress.GW)) == ERROR_SUCCESS ))
{
wprintf(L"ERROR IN DefaultGateway OPEN\r\n");
}

//Close the Registry Key
RegCloseKey (hKey);
}

//Open the Handle to Rebind the Network Adapter
HANDLE hNdis = CreateFile(_T("NDS0:"), GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, 0, NULL );
if (hNdis == NULL)
{
wprintf(L"ERROR IN CreateFile\r\n");
}
// ULONG Size=sizeof(AdapterInfo);
// GetAdaptersInfo(AdapterInfo,&Size);


TCHAR *str = TEXT("SMSC91181\0") ;

//Rebind the Network Adapter
if (!DeviceIoControl(hNdis, IOCTL_NDIS_REBIND_ADAPTER, str
,(_tcslen(str)+2) * sizeof(TCHAR), NULL, 0, &xcount, NULL ) )
{
//TCHAR str[100];
DWORD Error=::GetLastError();
wprintf(L"ERROR IN DeviceIoControl: %d\r\n",Error);
}

//Close the Handle
CloseHandle(hNdis);
}
int _tmain(int argc, _TCHAR* argv[])
{
SetNetworkRegistry();
return 0;
}

Good Luck.
--
vinoth.R
http://vinoth-vinothblog.blogspot.com
http://www.e-consystems.com

Don

unread,
Jun 1, 2010, 1:11:01 PM6/1/10
to

Thankyou so much for your answer. I did compile a modified version of your
sample see below.

It keeps failing at DeviceIoControl when rebinding the adaptor. Do you have
any suggestions on what I could be doing wrong?

// StaticIP.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <Iphlpapi.h>
#include "Winsock2.h"

void SetNetworkRegistry(void);
void WriteStringToErrorLog(char *buffer);

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
WriteStringToErrorLog("\nWinMain");

SetNetworkRegistry();

return 0;
}

// SetAdaptorInfo.cpp : Defines the entry point for the console application.
//


#define IOCTL_NDIS_REBIND_ADAPTER 0x17002e

//IP_ADAPTER_INFO AdapterInfo[4];
typedef struct _ADDRESS_NETWORK
{
TCHAR IP[16];
TCHAR GW[16];
TCHAR SNM[16];

}ADDRESS_NETWORK;

ADDRESS_NETWORK gAddress;


//This will set the Ip address, Gateway address and SubnetMask Address
void SetNetworkRegistry(void)
{

LPVOID lpMsgBuf;


TCHAR szTemp[256];
HKEY hKey;
LONG hRes;
DWORD xcount;

WriteStringToErrorLog("\nSetNetworkRegistry Called");

_tcscpy (szTemp, TEXT("Comm\\PCI\\FETCE6B1\\Parms\\TcpIp"));

wcscpy(gAddress.IP,L"192.168.1.118");
wcscpy(gAddress.GW,L"192.168.1.1");

wcscpy(gAddress.SNM,L"255.255.255.0");
hKey = NULL;
//Open the registry Key
hRes = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szTemp, 0, 0, &hKey);
if (ERROR_SUCCESS == hRes && hKey != NULL)
{

// Set the IP Address Registry Setting
if(!(RegSetValueEx (hKey, TEXT("IpAddress"), 0, REG_MULTI_SZ, (const
UINT8*)gAddress.IP, sizeof(gAddress.IP)) == ERROR_SUCCESS ))
{

WriteStringToErrorLog("\nERROR IN IpAddress OPEN");


wprintf(L"ERROR IN IpAddress OPEN\r\n");

}

// Set the Subnet Mask Address Registry Setting
if(!(RegSetValueEx (hKey, TEXT("Subnetmask"), 0, REG_MULTI_SZ, (const
UINT8*)gAddress.SNM, sizeof(gAddress.SNM)) == ERROR_SUCCESS ))
{

WriteStringToErrorLog("\nERROR IN Subnetmask OPEN");


wprintf(L"ERROR IN Subnetmask OPEN\r\n");
}

// Set the gateway Address Registry Setting
if(!(RegSetValueEx (hKey, TEXT("DefaultGateway"), 0, REG_MULTI_SZ, (const
UINT8*)gAddress.GW, sizeof(gAddress.GW)) == ERROR_SUCCESS ))
{

WriteStringToErrorLog("\nERROR IN DefaultGateway OPEN");


wprintf(L"ERROR IN DefaultGateway OPEN\r\n");
}

//Close the Registry Key
RegCloseKey (hKey);
}

//Open the Handle to Rebind the Network Adapter
HANDLE hNdis = CreateFile(_T("NDS0:"), GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, 0, NULL );
if (hNdis == NULL)
{

WriteStringToErrorLog("\nERROR IN CreateFile");


wprintf(L"ERROR IN CreateFile\r\n");
}
// ULONG Size=sizeof(AdapterInfo);
// GetAdaptersInfo(AdapterInfo,&Size);


TCHAR *str = TEXT("FETCE6B1\0") ;

//Rebind the Network Adapter
if (!DeviceIoControl(hNdis, IOCTL_NDIS_REBIND_ADAPTER, str
,(_tcslen(str)+2) * sizeof(TCHAR), NULL, 0, &xcount, NULL ) )
{

WriteStringToErrorLog("\nERROR IN DeviceIoControl:");


//TCHAR str[100];
DWORD Error=::GetLastError();

wprintf(L"ERROR IN DeviceIoControl: %d\r\n",Error);
}

WriteStringToErrorLog("\nSetNetworkRegistry Retrurned");

//Close the Handle
CloseHandle(hNdis);
}

void WriteStringToErrorLog(char *buffer)
{
int i = 0;
FILE *fptr;
fptr = fopen( "\\Hard Disk2\\StaticIP.txt", "a");
for(i = 0; buffer[i]; i++);

fwrite(buffer,1,i,fptr);
fclose(fptr);
}
--
Don

KMOS

unread,
Jun 1, 2010, 4:07:08 PM6/1/10
to
Since it is a PCI based driver (according to your registry), the adaptor
string need a PCI\ prefix, thus the code should be updated as

TCHAR *str = TEXT("PCI\\FETCE6B1\0") ;

"Don" <D...@discussions.microsoft.com> wrote in message

news:2EDD0AF5-816B-4665...@microsoft.com...

Don

unread,
Jun 1, 2010, 4:25:01 PM6/1/10
to

Ok I got it. Thanks so much for your help. The solution for me was to

TCHAR *str = TEXT("\PCI\AdapterName\0") --

Now that the ip is changed I can no longer browse with Windows Explorer by
type

\\ipaddress

to see my CE device. I can ping from a DOS prompt from another pc on my
network running Windows XP. Do you have any idea why Windows explorer on
another pc would not be able to browse with using the new changed ip


Don

KMOS

unread,
Jun 1, 2010, 4:37:43 PM6/1/10
to
Assume you are using SMB server?
Have you tried to reload the service? such as

hSrvDev = CreateFile(L"SMB1:",


GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0, NULL);

DeviceIoControl(hSrvDev,IOCTL_SERVICE_REFRESH,
NULL,0,0,0,0,NULL);


"Don" <D...@discussions.microsoft.com> wrote in message

news:0BDEB720-46EF-4DD7...@microsoft.com...

Don

unread,
Jun 2, 2010, 3:36:02 PM6/2/10
to

That works. Thankyou so much for your help. It is very appreciated
--
Don


"KMOS" wrote:

> .
>

0 new messages