CxLocalHostIPAddrFind的使用如下:

XNET_API BOOL GetFirstValidIPAddress(LPTSTR lpszIPAddr)
{
    BOOL bValid = FALSE;
    CxLocalHostIPAddrFind find;
    BOOL bRet = find.FindIPAddr();
    while (bRet)
    {
        find.GetIPAddr(lpszIPAddr);
        bValid = IsValidIPAddress(lpszIPAddr);
        if (bValid)
            break;
        else
            bRet = find.FindNextIPAddr();
    }
    find.FindIPAddrClose();
    
    return bRet;
}

然后在需要的地方调用此函数:

BOOL CO2CPbySocket::ListenRemoteHost()
{
    TCHAR szIPAddr[NET_HOST_MAX_IPV6];
    if (::GetFirstValidIPAddress(szIPAddr))
        return m_ssLocalHost.ListenConnection(szIPAddr, NETPORT_NETWORK_COMM);
    else
        return FALSE;
}

  精练的代码不需要过多解释,你们懂的。To be continued...

下载

libComm - v1.2 For WinXP/Win7

相关文章:

  • 2021-11-28
  • 2021-06-17
  • 2021-05-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-12-24
  • 2021-12-24
猜你喜欢
  • 2021-12-24
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2021-12-24
相关资源
相似解决方案