delphi 查找拨号设备是否成功

//判断拨号连接
unit UnitRasEnumConnection;


interface
uses
  Windows,SysUtils;
const
  RAS_MaxDeviceType = 16; //设备类型名称长度
  RAS_MaxEntryName = 256; //连接名称最大长度
  RAS_MaxDeviceName = 128; //设备名称最大长度
type
  RASCONN = record //活动的拨号连接的句柄和设置信息
    dwSize: DWORD; //该结构所占内存的大小(Bytes), 一般设置为SizeOf(RASCONN)
    hrasconn: DWORD; //活动连接的句柄
    szEntryName: array[0..RAS_MaxEntryName] of char; //活动连接的名称
    szDeviceType: array[0..RAS_MaxDeviceType] of char; //活动连接的所用的设备类型
    szDeviceName: array[0..RAS_MaxDeviceName] of char; //活动连接的所用的设备名称
  end;


function RasEnumConnections(var lprasconn: RASCONN; //接收活动连接的缓冲区的指针
  var lpcb: DWORD; //缓冲区大小
  var lpcConnections: DWORD //实际的活动连接数
  ): DWORD; stdcall;
function RasEnumConnections; external 'Rasapi32.dll' name 'RasEnumConnectionsA'; //获取指定活动的拨号连接的动态IP信息function RasGetProjectionInfo(    hrasconn : HRasConn;//指定活动连接的句柄    rasprojection : DWORD;//RAS连接类型    var  lpprojection : TRASPPPIP;//接收动态IP信息的缓冲区    var  lpcb : DWord//接收缓冲区的大小   ) : DWORD;stdcall;function RasGetProjectionInfo;external Rasapi32.dll name RasGetProjectionInfoA;


function RasEnumConnection: Boolean;


implementation


function RasEnumConnection: Boolean;
const
  MaxConnections = 10; //假设最多有10个活动的拨号连接
var connections: array[0..MaxConnections - 1] of RASCONN; //拨号连接数组
  longSize: dword;
  intAvailabelConnections: dword; //活动的拨号连接的实际数目
  intIndex: integer;
  strTemp: string;
  dwResult: DWORD;
 // RASpppIP: TRASPPPIP; //活动的拨号连接的动态IP地址信息
begin
  Result := false;
  connections[0].dwSize := sizeof(RASCONN);
  longSize := MaxConnections * connections[0].dwSize; //接收活动连接的缓冲区大小
  intAvailabelConnections := 0; //获取所有活动的拨号连接的信息(连接句柄和设置信息)
  dwResult := RasEnumConnections(connections[0], longSize, intAvailabelConnections);
  if 0 <> dwResult then
    Result := false
  else
  begin
   for intIndex := 0 to intAvailabelConnections - 1 do
    begin //?
      if StrPAS(connections[intIndex].szDeviceName) = 'HUWEI Modem' then
        Result := true;
     //显示一个活动的拨号连接的设置信息
//      strTemp := '连接名称:' + StrPAS(connections[intIndex].szEntryName)
//        + ',设备类型:' + StrPAS(connections[intIndex].szDeviceType)
//        + ',设备名称: ' + StrPAS(connections[intIndex].szDeviceName);
    end;
  end;
end;
end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值