InternetCheckConnection always return false

雨燕双飞 提交于 2019-12-23 20:10:35

问题


I want to use the Wininet function InternetCheckConnection to check whenever the machine is connected to the internet and can access a specific host. The problem is that this function is always returning false, no matter the URL I put on it.

MSDN link


回答1:


Following combination works for me on Windows 7 and Windows XP SP3:

 InternetCheckConnection("http://www.google.com", FLAG_ICC_FORCE_CONNECTION, 0) ;

GetLastError() returns 0 if the connexion is possible and it returns 12029 (The attempt to connect to the server failed) if not.

Following combonations don't work for me :

  InternetCheckConnection(NULL, FLAG_ICC_FORCE_CONNECTION, 0) ;

GetLastError() returns 12016 (The requested operation is invalid).

  InternetCheckConnection(NULL, 0, 0) ;
  InternetCheckConnection(("http://www.google.com", 0, 0) ;

for both GetLastError() returns 2250 (The network connection could not be found).




回答2:


Have you checked GetLastError() ? If I read MSDN correctly, you would need to check for ERROR_NOT_CONNECTED to determine whether you're truly offline.




回答3:


Just a wild guess, but perhaps this is due to a personal firewall blocking all outgoing connections for one of the Windows DLLs and / or your application?



来源:https://stackoverflow.com/questions/560771/internetcheckconnection-always-return-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!