转:WinCE6.0 不重启修改IP地址

采用修改注册表的方式实现:

 

在应用程序中修改IP地址的方式:

 1 //
 2 // Set IP Address, Mask and Gateway 
 3 // Through the registry entry:
 4 // [HKEY_LOCAL_MACHINE/Comm/DM9CE1/Parms/TcpIp]
 5 // IpAddress, String
 6 // SubnetMask, String
 7 // DefaultGateway, String
 8 //
 9 SYSTEMUTILITY_API BOOL SysUtil_IPConfig(LPCWSTR m_StrIPAddress, LPCWSTR m_StrIPMask, LPCWSTR m_StrGate)
10 {
11     long lResult = 0;
12 
13     HANDLE hIPCEvent = CreateEvent(NULL, TRUE, FALSE, NULL); ;
14     LPCTSTR    strSubKeyName = _T("Comm//DM9CE1//Parms//TcpIp");
15     LPCTSTR strAdapterName = _T("DM9CE1");
16     LPCTSTR strIP = _T("IpAddress");
17     LPCTSTR strMask = _T("SubnetMask");
18     LPCTSTR strGate = _T("DefaultGateway");
19     LPCTSTR strDHCP = _T("EnableDHCP");
20     DWORD dwValue = 0;
21 
22     DWORD dwStatus = NotifyAddrChange(&hIPCEvent, NULL);
23     if(dwStatus != NO_ERROR)
24         return FALSE;
25 
26     // Change IP Settings
27     HKEY hKey;
28     DWORD dwStrLen = 0;
29     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKeyName, 0, 0, &hKey) == ERROR_SUCCESS)
30     {
31         dwStrLen = wcslen(m_StrIPAddress) * sizeof(WCHAR);
32         lResult = RegSetValueEx(hKey, strIP, 0, REG_SZ, (LPBYTE)m_StrIPAddress, dwStrLen);
33         if(lResult != ERROR_SUCCESS)
34             return FALSE;
35 
36         dwStrLen = wcslen(m_StrIPMask) * sizeof(WCHAR);
37         lResult = RegSetValueEx(hKey, strMask, 0, REG_SZ, (LPBYTE)m_StrIPMask, dwStrLen);
38         if(lResult != ERROR_SUCCESS)
39             return FALSE;
40 
41         dwStrLen = wcslen(m_StrGate) * sizeof(WCHAR);
42         lResult = RegSetValueEx(hKey, strGate, 0, REG_SZ, (LPBYTE)m_StrGate, dwStrLen);
43         if(lResult != ERROR_SUCCESS)
44             return FALSE;
45 
46         dwStrLen = sizeof(dwValue);
47         lResult = RegSetValueEx(hKey, strDHCP, 0, REG_DWORD, (LPBYTE)&dwValue, dwStrLen); 
48         if(lResult != ERROR_SUCCESS)
49             return FALSE;
50 
51         RegCloseKey(hKey);
52     }
53 
54     // Rebind NDIS
55     if(!RebindNdisAdapter(strAdapterName))
56         return FALSE;
57 
58     // Waiting until they are applied
59     if(WaitForSingleObject(hIPCEvent, WAIT_TIMEOUT_10S) != WAIT_OBJECT_0)
60         return FALSE;
61 
62     CloseHandle(hIPCEvent);
63 
64     return TRUE;
65 }

 

转载于:https://www.cnblogs.com/killer-xc/p/6692237.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值