Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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,

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 ValueReturns TRUE if there is an Internet connection, or FALSE otherwise.

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,

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 );
}

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

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.

![]() |
![]() |
![]() |

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