问题
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