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
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With