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.
BOOL InternetCheckConnection( LPCTSTR lpszUrl, DWORD dwFlags, DWORD dwReserved );
Parameters
-
lpszUrl
- [in] Pointer to