Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Is P/Invoke InternetGetConnectedState cached?
I'm working with the compact framework and needed to use P/Invoke functionality for finding whether or not the mobile device is connected to the internet. The connection status always seems to appear as if it is connected (through a LAN) even though the wireless is turned off and has no connection at all. Do you know if the status is cached anywhere or what I'm doing wrong?
Heres the code I have:
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
private extern static bool InternetGetConnectedState(ref InternetConnectionState lpdwFlags, int dwReserved);
enum InternetConnectionState: int
INTERNET_CONNECTION_MODEM = 0x01,
INTERNET_CONNECTION_LAN = 0x02,
INTERNET_CONNECTION_PROXY = 0x04,
INTERNET_CONNECTION_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
InternetConnectionState flags = 0;
private void btnConnection_Click(object sender, EventArgs e)
bool isConnected = InternetGetConnectedState(ref flags, 0);
bool isConfigured = (flags & InternetConnectionState.INTERNET_CONNECTION_CONFIGURED) != 0;
bool isOffline = (flags & InternetConnectionState.INTERNET_CONNECTION_OFFLINE) != 0;
bool isConnectedUsingModem = (flags & InternetConnectionState.INTERNET_CONNECTION_MODEM) != 0;
bool isConnectedUsingLAN = (flags & InternetConnectionState.INTERNET_CONNECTION_LAN) != 0;
bool isProxyUsed = (flags & InternetConnectionState.INTERNET_CONNECTION_PROXY) != 0;
and the listbox2 returns:
0 · ·