1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <Wininet.h>
#pragma comment(lib,"Wininet.lib" )
BOOL TestConnexion(void)
{
DWORD flags;
HINTERNET hInternetSession, hHttpSession;
flags = INTERNET_CONNECTION_OFFLINE;
BOOL connected = InternetGetConnectedState(&flags, 0);
//if (connected) connected = ! InternetCheckConnection("http://www.google.fr", INTERNET_CONNECTION_OFFLINE, 0);
if (connected)
{
connected = FALSE;
hInternetSession = InternetOpen ("test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL) ;
if (hInternetSession)
{
hHttpSession = InternetOpenUrl( hInternetSession, "http://www.google.com", NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0 ) ;
connected = hHttpSession != FALSE;
if (connected) InternetCloseHandle( hHttpSession );
}
InternetCloseHandle (hInternetSession) ;
}
return connected;
} |
Partager