如何将IP地址转换成字符串

2025-05-10 14:56:54
推荐回答(1个)
回答1:

//将CString 型IP地址在IPAddressCtrl中显示
CString strIP="192.168.1.1";
DWORD dwIP;
dwIP = inet_addr(strIP);
unsigned char *pIP = (unsigned char*)&dwIP;
m_ipAddr.SetAddress(*pIP, *(pIP+1), *(pIP+2), *(pIP+3));

//将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);