CString GetIPStringFromDWORD(DWORD IP)
{
CString strA(_T("")), strB(_T("")), strC(_T("")), strD(_T(""));
DWORD dwIP = IP;
strD.Format(_T(".%d"), dwIP % 256);
dwIP /= 256;
strC.Format(_T(".%d"), dwIP % 256);
dwIP /= 256;
strB.Format(_T(".%d"), dwIP % 256);
dwIP /= 256;
strA.Format(_T("%d"), dwIP % 256);
return strA + strB + strC + strD;
}
{
CString strA(_T("")), strB(_T("")), strC(_T("")), strD(_T(""));
DWORD dwIP = IP;
strD.Format(_T(".%d"), dwIP % 256);
dwIP /= 256;
strC.Format(_T(".%d"), dwIP % 256);
dwIP /= 256;
strB.Format(_T(".%d"), dwIP % 256);
dwIP /= 256;
strA.Format(_T("%d"), dwIP % 256);
return strA + strB + strC + strD;
}
本文介绍了一个简单的函数,用于将32位整数(DWORD)格式的IPv4地址转换为标准的点分十进制字符串形式。通过逐步拆分整数并进行格式化,最终得到如'192.168.1.1'这样的常见IP地址表示。

1万+

被折叠的 条评论
为什么被折叠?



