Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InternetCheckConnection always return false

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

like image 200
gmuller Avatar asked Dec 13 '25 19:12

gmuller


2 Answers

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).

like image 89
Jabberwocky Avatar answered Dec 16 '25 22:12

Jabberwocky


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.

like image 29
MSalters Avatar answered Dec 16 '25 22:12

MSalters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!