C# .NET - WIN API Internet Get Connected State

Asked By Paul Abraham on 25-Jun-04 12:15 PM
Something   Strange

enum InternetConnectionState: int
	{
		INTERNET_CONNECTION_MODEM = 0x1,
		INTERNET_CONNECTION_LAN = 0x2,
		INTERNET_CONNECTION_PROXY = 0x4,
		INTERNET_RAS_INSTALLED = 0x10,
		INTERNET_CONNECTION_OFFLINE = 0x20,
		INTERNET_CONNECTION_CONFIGURED = 0x40
	}


// import WIN API functions
[DllImport("wininet.dll", CharSet=CharSet.Auto)]
static extern bool InternetGetConnectedState(
ref InternetConnectionState lpdwFlags, 
 int dwReserved);

		/// </summary>
		/// <returns></returns>
public static bool IsConnected( )
{
   bool bConnected=false;
   InternetConnectionState flags = 0;        bConnected=InternetGetConnectedState(ref flags,0) ;
			
return bConnected;


}


I am checking  using  the  InternetGetConnectedState WIN API  function     whether the local machine  is connected to internet or not.  It works well, but not in  this special case. If  I connect to internet  and disconnect it manually, then  the  IsConnected method return still true value. What is wrong with the code?

Thank you

Don't you need to "OR" together the flags enums? - Asked By Peter Bromberg on 25-Jun-04 01:28 PM

e.g. in your sample you are passing in "0" for INTERNET_CONNECTION_MODEM only.
What about LAN?