Click to See Complete Forum and Search --> : iPAQ: auto network detection/checking


joko71
July 29th, 2002, 07:13 AM
This code should detect internet connection, but in my case fails, wrongly
assumes there is an active network. What changes should I make in order to
work?

int CheckInternetConnection()
{
unsigned long flags;

return TRUE;

if(InternetGetConnectedState(&flags, 0) == FALSE)
{
return FALSE;
}
else
{
HINTERNET hInet = InternetOpen(_T("TestAgent"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hInetFile = InternetOpenUrl(hInet, _T(http://www.microsoft.com),
NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);

//Attempt connection
if(hInetFile == NULL)
{
DWORD err;

// Call failed
err = GetLastError();

if ((err == ERROR_INTERNET_NAME_NOT_RESOLVED) ||
(err == ERROR_INTERNET_CANNOT_CONNECT) ||
(err == ERROR_INTERNET_TIMEOUT))
{
return FALSE;
}
}
// We're connected!!!
}

return TRUE;
}