ADSL自动拨号类,前提是在系统中已经有了一个宽带拨号连接

调用代码:

RASDisplay ras = new RASDisplay();

ras.Disconnect();//断线

ras.Connect("adsl");//拨号

using System;

using System.Runtime.InteropServices;

public struct RASCONN

{

public int dwSize;

public IntPtr hrasconn;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=257)]

public string szEntryName;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=17)]

public string szDeviceType;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=129)]

public string szDeviceName;

}

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]

public struct RasStats

{

public int dwSize;

public int dwBytesXmited;

public int dwBytesRcved;

public int dwFramesXmited;

public int dwFramesRcved;

public int dwCrcErr;

public int dwTimeoutErr;

public int dwAlignmentErr;

public int dwHardwareOverrunErr;

public int dwFramingErr;

public int dwBufferOverrunErr;

public int dwCompressionRatioIn;

public int dwCompressionRatioOut;

public int dwBps;

public int dwConnectionDuration;

}

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]

public struct RasEntryName

{

public int dwSize;

//[MarshalAs(UnmanagedType.ByValTStr,SizeConst=(int)RasFieldSizeConstants.RAS_MaxEntryName + 1)]

public string szEntryName;

//#if WINVER5

//  public int dwFlags;

//  [MarshalAs(UnmanagedType.ByValTStr,SizeConst=260+1)]

//  public string szPhonebookPath;

//#endif

}

public class RAS

{

[DllImport("RaSAPi32.dll", EntryPoint="RasEnumConnectionsA",

SetLastError=true)]

internal static extern int RasEnumConnections

(

ref RASCONN lprasconn, // buffer to receive connections data

ref int lpcb, // size in bytes of buffer

ref int lpcConnections // number of connections written to buffer

);

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]

internal static extern uint RasGetConnectionStatistics(

IntPtr hRasConn,       // handle to the connection

[In,Out]RasStats lpStatistics  // buffer to receive statistics

);

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]

public extern static uint RasHangUp(

IntPtr hrasconn  // handle to the RAS connection to hang up

);

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]

public extern static uint RasEnumEntries (

string reserved,              // reserved, must be NULL

string lpszPhonebook,         // pointer to full path and

//  file name of phone-book file

[In,Out]RasEntryName[] lprasentryname, // buffer to receive

//  phone-book entries

ref int lpcb,                  // size in bytes of buffer

out int lpcEntries             // number of entries written

//  to buffer

);

[DllImport("wininet.dll",CharSet=CharSet.Auto)]

public extern static int InternetDial(

IntPtr hwnd,

[In]string lpszConnectoid,

uint dwFlags,

ref int lpdwConnection,

uint dwReserved

);

public RAS()

{

}

}

public enum DEL_CACHE_TYPE //要删除的类型。

{

File,//表示internet临时文件

Cookie //表示Cookie

};

public class RASDisplay

{

[DllImport("wininet.dll",CharSet=CharSet.Auto)]

public static extern bool  DeleteUrlCacheEntry(

DEL_CACHE_TYPE type

);

private string m_duration;

private string m_ConnectionName;

private string[] m_ConnectionNames;

private double m_TX;

private double m_RX;

private bool m_connected;

private IntPtr m_ConnectedRasHandle;

RasStats status = new RasStats();

public RASDisplay()

{

m_connected = true;

RAS lpras = new RAS();

RASCONN lprasConn = new RASCONN();

lprasConn.dwSize = Marshal.SizeOf(typeof(RASCONN));

lprasConn.hrasconn = IntPtr.Zero;

int lpcb = 0;

int lpcConnections = 0;

int nRet = 0;

lpcb = Marshal.SizeOf(typeof(RASCONN));

nRet = RAS.RasEnumConnections(ref lprasConn, ref lpcb, ref

lpcConnections);

if(nRet != 0)

{

m_connected = false;

return;

}

if(lpcConnections > 0)

{

//for (int i = 0; i

//{

RasStats stats = new RasStats();

m_ConnectedRasHandle = lprasConn.hrasconn;

RAS.RasGetConnectionStatistics(lprasConn.hrasconn, stats);

m_ConnectionName = lprasConn.szEntryName;

int Hours = 0;

int Minutes = 0;

int Seconds = 0;

Hours = ((stats.dwConnectionDuration /1000) /3600);

Minutes = ((stats.dwConnectionDuration /1000) /60) - (Hours * 60);

Seconds = ((stats.dwConnectionDuration /1000)) - (Minutes * 60) - (Hours * 3600);

m_duration = Hours  +  " hours "  + Minutes + " minutes " + Seconds + " secs";

m_TX = stats.dwBytesXmited;

m_RX = stats.dwBytesRcved;

//}

}

else

{

m_connected = false;

}

int lpNames = 1;

int entryNameSize = 0;

int lpSize = 0;

RasEntryName[] names = null;

entryNameSize=Marshal.SizeOf(typeof(RasEntryName));

lpSize=lpNames*entryNameSize;

names=new RasEntryName[lpNames];

names[0].dwSize=entryNameSize;

uint retval = RAS.RasEnumEntries(null,null,names,ref lpSize,out lpNames);

//if we have more than one connection, we need to do it again

if(lpNames > 1)

{

names=new RasEntryName[lpNames];

for(int i=0;i

{

names[i].dwSize=entryNameSize;

}

retval = RAS.RasEnumEntries(null,null,names,ref lpSize,out lpNames);

}

m_ConnectionNames = new string[names.Length];

if(lpNames>0)

{

for(int i=0;i

{

m_ConnectionNames[i] = names[i].szEntryName;

}

}

}

public string Duration

{

get

{

return m_connected ? m_duration : "";

}

}

public string[] Connections

{

get

{

return m_ConnectionNames;

}

}

public double BytesTransmitted

{

get

{

return m_connected ? m_TX : 0;

}

}

public double BytesReceived

{

get

{

return m_connected ? m_RX :  0;

}

}

public string ConnectionName

{

get

{

return m_connected ? m_ConnectionName : "";

}

}

public bool IsConnected

{

get

{

return m_connected;

}

}

public int Connect(string Connection)

{

int temp = 0;

uint INTERNET_AUTO_DIAL_UNATTENDED = 2;

int retVal = RAS.InternetDial(IntPtr.Zero,Connection,INTERNET_AUTO_DIAL_UNATTENDED,ref temp,0);

return retVal;

}

public void Disconnect()

{

RAS.RasHangUp(m_ConnectedRasHandle);

}

}

c语言adsl拨号写法,用C#写的ADSL拨号程序的代码示例相关推荐

  1. 简单介绍三个C语言图形库C语言其实最擅长的是写纯数据处理的程序 . 非得用C语言写个界面程序那将会变得很困难 . 我刚开始学C语言就是从hello world 开始的 , 后来慢慢开始学从三个数中找

    C语言其实最擅长的是写纯数据处理的程序 . 非得用C语言写个界面程序那将会变得很困难 . 我刚开始学C语言就是从hello world 开始的 , 后来慢慢开始学从三个数中找出最大值 , 和对数组进行 ...

  2. 位置关系C语言,C++/STL实现判断平面内两条线段的位置关系代码示例

    概念 平面内两条线段位置关系的判定在很多领域都有着广泛的应用,比如游戏.CAD.图形处理等,而两线段交点的求解又是该算法中重要的一环.本文将尽可能用通俗的语言详细的描述一种主流且性能较高的判定算法. ...

  3. c语言数组读心术,无聊的时候写的读心术小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include int main(void) { while(1) { system("cls" ...

  4. c语言读心术原理,无聊的时候写的读心术小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include int main(void) { while(1) { system("cls" ...

  5. c语言重画清屏函数,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...

  6. c语言gotoxy函数是什么意思,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教...

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...

  7. 写一个微信小程序的代码

    微信小程序是使用小程序框架开发的,主要使用 WXML 和 WXSS 两种语言构建用户界面,使用 JavaScript 来编写逻辑. 以下是一个简单的微信小程序示例代码: <!-- index.w ...

  8. c语言实现单链表逆序算法,C语言解字符串逆序和单向链表逆序问题的代码示例...

    字符串逆序上次面试碰到一个单向链表逆序的题目,幸好对字符串逆序比较熟悉,类比做出来了.字符串逆序比较简单,直接上代码: void stringReverse(char* p1,char* p2) { ...

  9. python中ln怎么写_Python Decimal ln()用法及代码示例

    Decimal#ln():ln()是一个Decimal类方法,它返回Decimal值的自然(对数e)对数. 用法:Decimal.ln() 参数:十进制值 返回:十进制值的自然(以e为底)对数. 代码 ...

最新文章

  1. vb6 获得计算机硬件信息_计算机硬件系统由哪几部分组成
  2. WEB端后台常用Axure元件库及框架模版
  3. steam插件_Steam是如何了解一款游戏的?看了这篇文章会让你豁然开朗!
  4. 苹果手机怎么投屏王者荣耀
  5. CDD数据库文件制作(三)——DID
  6. 【破解手记】普利尼,破解手记[1]
  7. windows云服务器,如何使用windows云服务器
  8. BILIBILI 高并发实时弹幕系统那些事(项目开源、架构演变)
  9. Request对象的一般用法
  10. python安装anacondapanda_关于pandas:Pyarrow不安装python 3.7(anaconda 5.3.0,windows x64版本)...
  11. 微信怎样查绑定的服务器地址,你的微信绑定了哪些网站和应用?这个方法可以一键查看......
  12. 顺序结构、选择结构、循环结构
  13. prompt learning 提示学习初步心得及示例 代码
  14. AIX各项知识链接(IBM官网)
  15. qduoj 生化危机ycb老师的电脑中毒了(邻接表)
  16. 高中在线计算机,高中计算机考试试题集-20210414015151.docx-原创力文档
  17. Easyrecovery汉化版下载
  18. HTML5网页设计练习
  19. golang channel
  20. 3Dmax到UE4制作入门到精通

热门文章

  1. 川西红叶:谁能抵挡如此色诱
  2. python数据透视表怎么存下来_python-从存储在两个数据框中的两个数据透视表中减去值...
  3. 西门子新一代HMI操作面板功能说明
  4. 如何使用服务器跑程序
  5. 三轴桁架机械手控制系统 用于数控车床自动上下料
  6. VMware-Ubuntu连接U盘
  7. POJ1151 Atlantis(线段树,扫描线,离散化,矩形面积并)
  8. 怎样用SoapUI测试接口
  9. Portal Rendering与镜子特效
  10. 开发中常用到adb命令