IP转换(u_long与CString 互转)

void CNewClientTestDlg::nIPTostrIP(DWORD nIP,char * strIP)
{
    sprintf(strIP,"%u.%u.%u.%u", 
        LOBYTE(LOWORD(nIP)),
        HIBYTE(LOWORD(nIP)),
        LOBYTE(HIWORD(nIP)),
        HIBYTE(HIWORD(nIP)));                
}

void CNewClientTestDlg::strIPTonIP(DWORD &nIP,char * strIP)
{
    DWORD    bIP[4];        // 一定要为DWORD
    
    sscanf(strIP,"%u.%u.%u.%u",
        &bIP[3],
        &bIP[2],
        &bIP[1],
        &bIP[0]);
    
    nIP = MAKELONG(MAKEWORD(bIP[3],bIP[2]),MAKEWORD(bIP[1],bIP[0]));
}

你可能感兴趣的:(IP转换(u_long与CString 互转))