InternetCheckConnection 通过尝试连接特定的网址,可以用来判断目前机器是否接通外网

InternetCheckConnection 通过尝试连接特定的网址,可以用来判断目前机器是否接通外网。例如:

BOOL bConnected = InternetCheckConnection(_T("http://www.google.com"), FLAG_ICC_FORCE_CONNECTION, 0);

使用时第二个参数一定要设置为FLAG_ICC_FORCE_CONNECTION,这样才会尝试去建立连接。当目标地址不可用时,这个函数返回会比较慢,注意不要在UI线程中使用。

这个函数会解析出URL中的host地址,然后建立socket连接去ping这个地址。

InternetCheckConnection

Allows an application to check if a connection to the Internet can be established.

<strong>BOOL InternetCheckConnection(
  LPCTSTR</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/harbinzju/article/details/6956814" style="color: rgb(202, 0, 0); text-decoration: none;">lpszUrl</a></em><strong>,
  DWORD</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/harbinzju/article/details/6956814" style="color: rgb(202, 0, 0); text-decoration: none;">dwFlags</a></em><strong>,
  DWORD</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/harbinzju/article/details/6956814" style="color: rgb(202, 0, 0); text-decoration: none;">dwReserved</a></em><strong>
);</strong>
Parameters
lpszUrl
[in] Pointer to a null-terminated string that specifies the URL to use to check the connection. This value can be NULL.
dwFlags
[in] Options. FLAG_ICC_FORCE_CONNECTION is the only flag that is currently available. If this flag is set, it forces a connection. A sockets connection is attempted in the following order:
  • If lpszUrl is non-NULL, the host value is extracted from it and used to ping that specific host.
  • If lpszUrl is NULL and there is an entry in the internal server database for the nearest server, the host value is extracted from the entry and used to ping that server.
dwReserved
[in] Reserved. Must be zero.
Return Values
Returns  TRUE  if a connection is made successfully, or  FALSE  otherwise. Use  GetLastError  to retrieve the error code. ERROR_NOT_CONNECTED is returned by  GetLastError  if a connection cannot be made or if the sockets database is unconditionally offline.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值