IP地址的CString型和DWORD型转换

来源:互联网 发布:小公司网络组建 编辑:程序博客网 时间:2024/05/24 06:23

#pragma comment(lib,"ws2_32.lib")#include <Winsock2.h>//将CString 型IP地址在IPAddressCtrl中显示 CString strIP="192.168.0.10"; DWORD dwIP; dwIP = inet_addr(strIP); unsigned char *pIP = (unsigned char*)&dwIP; m_ipAddr.SetAddress(*(pIP+3), *(pIP+2), *(pIP+1), *pIP);       //将IPAddressCtrl中的IP地址获得并转换成CString型 unsigned char *pIP; CString strIP; DWORD dwIP; m_ipAddr.GetAddress(dwIP); pIP = (unsigned char*)&dwIP; strIP.Format("%u.%u.%u.%u",*(pIP+3), *(pIP+2), *(pIP+1), *pIP);//CString型IP地址转换为DWORDCString strIP="192.168.1.184"; DWORD dwAddress= ntohl( inet_addr(strIP)); m_IPAddr.SetAddress(dwAddress);// DWORD IP转换为CStringDWORD dwMainServerIP;m_MainServerIPCtrl.GetAddress(dwMainServerIP);strMainServerIP.Format(_T("%d.%d.%d.%d"), (dwMainServerIP>>24)&0xff, (dwMainServerIP>>16)&0xff, (dwMainServerIP>>8)&0xff, dwMainServerIP&0xff ) ;


0 0
原创粉丝点击