Computing.Net > Forums > Windows NT > C code for InternetGetConnectedState

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C code for InternetGetConnectedState

Reply to Message Icon

Name: Jack
Date: September 11, 2000 at 17:44:24 Pacific
Comment:

Hi,
Does anyone know a function other than InternetGetConnectedState() that gives the info for online or offline. I used InternetGetConnectedState(&stat, 0) and it always return TRUE no matter I disconnect the LAN connection or not.

Thanks,



Sponsored Link
Ads by Google

Response Number 1
Name: DoOMsdAY
Date: September 12, 2000 at 08:15:46 Pacific
Reply:

Are you using the proper connection flag(s)? From MSDN:



lpdwFlags
Address of an unsigned long integer variable where the connection description should be returned. This can be a combination of the following values:
INTERNET_CONNECTION_CONFIGURED
Local system has a valid connection to the Internet, but it may or may not be currently connected.
INTERNET_CONNECTION_LAN
Local system uses a local area network to connect to the Internet.
INTERNET_CONNECTION_MODEM
Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM_BUSY
No longer used.
INTERNET_CONNECTION_OFFLINE
Local system is in offline mode.
INTERNET_CONNECTION_PROXY
Local system uses a proxy server to connect to the Internet.
INTERNET_RAS_INSTALLED
Local system has RAS installed.
dwReserved
Reserved. Must be set to zero.
Return Value

Returns TRUE if there is an Internet connection, or FALSE otherwise.


0

Response Number 2
Name: Jack
Date: September 12, 2000 at 10:49:32 Pacific
Reply:

Yes, I've looked at the function description in MSDN. I have

DWORD bResult
bResult=InternetGetConnectedState(&stat, 0)

and I also tried declaring bResult as unsigned long int (which you suggested), but no matter what, bResult is always 1 (true). I was wondering if there's an alternative way to detect network online/offline.

thank you,



0

Response Number 3
Name: DoOMsdAY
Date: September 12, 2000 at 11:44:58 Pacific
Reply:

The actual prototype looks like:



BOOL InternetGetConnectedState(
   OUT LPDWORD lpdwFlags,
   IN DWORD dwReserved
);


Try something like:


BOOL  BSuccess;
DWORD DWFlags;

BSuccess = InternetGetConnectedState( &DWFlags, 0 );
if ( !BSuccess )
{
   AfxMessageBox( "No Internet connection detected!", MB_OK | MB_ICONINFORMATION );
}


0

Response Number 4
Name: Jack
Date: September 12, 2000 at 13:54:13 Pacific
Reply:

Hi DoOMsdAY,

I tried your code and BSuccess is still always 1 (no matter if it's online or offline). Do you know any other functions that does the similiar detecting?

thank you,
~Jack


0

Response Number 5
Name: DoOMsdAY
Date: September 13, 2000 at 06:11:29 Pacific
Reply:

I tried to post this last night, but the web board decided it was time to suck again.

Are you on a LAN? It might be setting DWFlags to INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM when you're online and only INTERNET_CONNECTION_LAN when you're offline - or something of that sort. Try this then:



BOOL BSuccess;
DWORD DWFlags;
BSuccess = InternetGetConnectedState( &DWFlags, 0 );
if ( !BSuccess )
{
   AfxMessageBox( "No Internet connection detected!", MB_OK | MB_ICONINFORMATION );
}
else
{
   if ( ( DWFlags & INTERNET_CONNECTION_LAN ) == INTERNET_CONNECTION_LAN )
   {
      AfxMessageBox( "Lan connection is present.", MB_OK );
   }

   if ( ( DWFlags & INTERNET_CONNECTION_MODEM ) == INTERNET_CONNECTION_MODEM )
   {
      AfxMessageBox( "Modem connection is present.", MB_OK );
   }
}



And no, I don't know any other way to check. I didn't even know of this way as I've never had to write any code to do this before. Am simply trying to figure out the API call as I would if I DID have to write something to do this.

0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows NT Forum Home


Sponsored links

Ads by Google


Results for: C code for InternetGetConnectedState

C compiler for WinNT targeting Netware www.computing.net/answers/windows-nt/c-compiler-for-winnt-targeting-netware/15223.html

Does anyone have the CD codes for NT? www.computing.net/answers/windows-nt/does-anyone-have-the-cd-codes-for-nt/12351.html

Need C API for www.computing.net/answers/windows-nt/need-c-api-for-/21623.html