BOOL CIpSetDlg::RegSetIP(CString pIPAddress,CString pNetMask,CString pNetGate)//静态更改注册表信息
{
HKEY hKey;
CString strKeyName =L"COMM//PCI//R60401//Parms//TCPIP//";
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
strKeyName,
0,
KEY_WRITE,
&hKey) != ERROR_SUCCESS)
return FALSE;
WCHAR mszIPAddress[100]={0};
WCHAR mszNetMask[100]={0};
WCHAR mszNetGate[100]={0};
wcsncpy(mszIPAddress,pIPAddress.GetBuffer(pIPAddress.GetLength()),pIPAddress.GetLength());
wcsncpy(mszNetMask,pNetMask.GetBuffer(pNetMask.GetLength()),pNetMask.GetLength());
wcsncpy(mszNetGate,pNetGate.GetBuffer(pNetGate.GetLength()),pNetGate.GetLength());
pIPAddress.ReleaseBuffer();
pNetMask.ReleaseBuffer();
pNetGate.ReleaseBuffer();
int nIP, nMask, nGate;
nIP = wcslen(mszIPAddress);
nMask = wcslen(mszNetMask);
nGate = wcslen(mszNetGate);
DWORD dhcpvalue=0x0;
RegSetValueEx(hKey,L"EnableDHCP", 0, REG_DWORD,(LPBYTE)&dhcpvalue,4);
//RegSetValueEx(hKey,L"DhcpIPAddress", 0, REG_MULTI_SZ,(LPBYTE)mszIPAddress,nIP*2);
RegSetValueEx(hKey,L"IPAddress", 0, REG_MULTI_SZ,(LPBYTE)mszIPAddress,nIP*2);
//RegSetValueEx(hKey,L"DhcpSubnetMask", 0, REG_MULTI_SZ,(LPBYTE)mszNetMask, nMask*2);
RegSetValueEx(hKey,L"SubnetMask", 0, REG_MULTI_SZ,(LPBYTE)mszNetMask, nMask*2);
//RegSetValueEx(hKey,L"DhcpDefaultGateway", 0, REG_MULTI_SZ,(LPBYTE)mszNetGate, nGate*2);
RegSetValueEx(hKey,L"DefaultGateway", 0, REG_MULTI_SZ,(LPBYTE)mszNetGate, nGate*2);
//RegFlushKey(hKey);
RegCloseKey(hKey);
return TRUE;
}
BOOL CIpSetDlg::RegAutoSetIP()//dhcp自动获得IP注册表设置
{
HKEY hKey;
CString strKeyName =L"COMM//PCI//R60401//Parms//TCPIP//";
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
strKeyName,
0,
KEY_WRITE,
&hKey) != ERROR_SUCCESS)
return FALSE;
DWORD dhcpvalue=0x1;
RegSetValueEx(hKey,L"EnableDHCP", 0, REG_DWORD,(LPBYTE)&dhcpvalue,4);
RegCloseKey(hKey);
return TRUE;
}
BOOL CIpSetDlg::SetNewDhcpIP()//动态捕获IP
{
UpdateData(true);
ULONG context;
ULONG Inst;
IPAddr NewIP;
IPAddr NewMask;
DWORD dwIfIndex;
char buf[256];
IP_ADAPTER_INDEX_MAP AdaptMap;
GetAdapterIndex(L"PCI//R60401",&dwIfIndex);
AdaptMap.Index=dwIfIndex;
wcscpy(AdaptMap.Name,L"PCI//R60401");
IpReleaseAddress(&AdaptMap);
DeleteIPAddress(AdaptMap.Index+2);//删除静态的IP
IpRenewAddress(&AdaptMap);
return true;
}
BOOL CIpSetDlg::SetNewIP()//静态设置IP加到列表
{
UpdateData(true);
ULONG context;
ULONG Inst;
IPAddr NewIP;
IPAddr NewMask;
DWORD dwIfIndex;
char buf[256];
IP_ADAPTER_INDEX_MAP AdaptMap;
GetAdapterIndex(L"PCI//R60401",&dwIfIndex);
AdaptMap.Index=dwIfIndex;
wcscpy(AdaptMap.Name,L"PCI//R60401");
memset(buf,0,256);
wcstombs(buf,m_ip,m_ip.GetLength());//宽字节转多字节
NewIP=inet_addr(buf);
memset(buf,0,256);
wcstombs(buf,m_netmask,m_netmask.GetLength());//宽字节转多字节
NewMask=inet_addr(buf);
IpReleaseAddress(&AdaptMap);
AddIPAddress(NewIP,NewMask,AdaptMap.Index,&context,&Inst);
DeleteIPAddress(context-1);//删除上一次的IP
//IpRenewAddress(&AdaptMap);
return true;
}
wince6下不重启改IP
最新推荐文章于 2017-04-11 10:05:00 发布