几何尺寸与公差论坛

 找回密码
 注册
查看: 2392|回复: 0

【转帖】c#: 网络状态

[复制链接]
发表于 2007-8-1 14:06:21 | 显示全部楼层 |阅读模式
[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;
        }
    }
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-5-9 10:25 , Processed in 0.035750 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表