菜鳥學堂:幫助你快速入門web開發! 最全面的通用函數集!
1.
方法定義
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;
2.
方法說明
參數:
connectionDescription : 連接說明
reservedValue : 保留值
返回值:
true: On Line
false: Off Line
3.
調用方法
a.
你必須在你的code裡引用System.Runtime.InteropServices,否則,會有編譯錯誤
b.
定義一個變量 int I = 0;
c.
調用bool state = InternetGetConnectedState(out I,0);
完整的代碼:
using System.Runtime.InteropServices;
namespace internet
{
public class Class1
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;
public Class1(){}
private bool IsConnected()
{
int I=0;
bool state = InternetGetConnectedState(out I,0);
return state;
}
}
}