|
判断PDA是否连接上网络,这个代码可以吗?哪个帮我实验一下,我用ActiveSync 连接的,这个判断可以吗?
private enum ConnectionStateEnum { //Local system has a valid connection to the Internet, but it might or might not be currently connected. ConnectionConfigured = 64, //Local system uses a local area network to connect to the Internet. ConnectionLan = 2, //Local system uses a modem to connect to the Internet. ConnectionModem = 1, //No longer used. ConnectionModemBusy = 8, //Local system is in offline mode. ConnectionOffline = 32, //Local system uses a proxy server to connect to the Internet. ConnectionProxy = 4, //Local system has RAS installed. RasInstalled = 16
}
class Win32 { [DllImport("Wininet.dll", CharSet = CharSet.Auto)] public static extern int InternetGetConnectedState(out int Flag, int Reserved); }
private static int GetConnectionFlag() { int Flag; Win32.InternetGetConnectedState(out Flag, 0); return Flag; }
public static bool IsModemConnected() { return ((GetConnectionFlag() & (int)ConnectionStateEnum.ConnectionModem) == 0) ? false : true; }
|