ADSL拨号控件—DLL版
发布于: 2012/12/15 9:44:50 | 发布在: Delphi第三方组件 | 点击:
使用TDialUp组件制作的一个DLL控件,该控件封装了使用PPPoE协议的ADSL拨号的常用功能,包括获取宽带连接列表,拨号,断线及反馈拨号消息及获取IP等功能。使用DLL控件管理ADSL拨号可以解决使用TDialUp组件有时会断开连接失败的问题。该DLL使用方法如下:
1. 将该DLL放在Delphi工程文件夹内。
2. 在工程中添加一个调用DLL的过程:
//通用调用过程
procedure Dial_Call(const csCmd, csConn: String; const aHandle: HWND);
var
strConn, strDllPath, strCmdLine: String;
begin
strConn := csConn;
strConn := StringReplace(strConn, ' ', '?', [rfReplaceAll]);
strDllPath := ExtractFilePath(Application.ExeName) + 'Dial.dll';
strCmdLine := Format('%s %s %d %s', [strDllPath, csCmd, aHandle, strConn]);
WinExec(PChar(strCmdLine), sw_normal);
end;
3. 调用通用过程进行拨号等操作:
procedure TForm1.Button1Click(Sender: TObject);
begin
Dial_Call('Get', '', Self.Handle); //获取连接列表
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Dial_Call('On', ComboBox1.Text, Self.Handle); //拨号
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Dial_Call('Off', '', 0); //断开连接
end;
4. 添加拨号消息响应代码:
//单元接口部分添加:
protected
procedure ReceiveResult(var t:TWmCopyData);message WM_COPYDATA;
//单元实现部分添加:
procedure TForm1.ReceiveResult(var t:TWmCopyData);
var
iCode: Integer;
str: String;
begin
iCode := t.From; //返回代码
str := StrPas(t.CopyDataStruct^.lpData); //接受数据并显示。
case iCode of
-2: ;//用户取消
-1: ExtractStrings(['|'], ['|'], PChar(str), ComboBox1.Items);//获取连接列表
0: ;//拨号成功,返回值为IP
else
//拨号出错
end;
Memo1.Text := str;
Edit1.Text := Format('返回代码:%d',[iCode]);
end;
附件:dial_dll.rar