Dll入门问题(200分!!)倾家荡产了。(200分)

  • 主题发起人 uranium235
  • 开始时间
U

uranium235

Unregistered / Unconfirmed
GUEST, unregistred user!
从编辑Dll文件到Dll接口和程序调用,
请高手给出一整套实例方便我等编程
菜鸟研究,特奉上200分!!

注:Dll不一定高难,只要例程明白,
解说详细,程序调用过程明确即可。
 
go www.playicq.com download
 
下载一个object pascal 入门教程,
不然给邮件地址,我给你发!
 
DLL编制实例(最简单的)
library P_dllexampl;

uses
SysUtils,
Classes;

{$R *.res}
function fun_add(p1,p2:integer):integer
stdcall;
begin
fun_add:=p1+p2;
end;

function fun_dec(p1,p2:integer):integer
stdcall;
begin
fun_dec:=p1-p2;
end;

exports
fun_add,
fun_dec;
begin
end.
 
DLL应用实例(2种调用方法都有):
unit dll_test;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
Edit3: TEdit;
Button2: TButton;
Button3: TButton;
Edit4: TEdit;
Edit5: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//直接使用外部函数--直接调用实例
function fun_add(p1,p2:integer):integer
stdcall;external 'P_dllexampl.dll';
function fun_dec(p1,p2:integer):integer
stdcall;external 'P_dllexampl.dll';

procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:='加';
edit3.Text:=inttostr(fun_add(strtoint(edit1.Text),strtoint(edit2.Text)));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
label1.Caption:='减';
edit3.Text:=inttostr(fun_dec(strtoint(edit1.Text),strtoint(edit2.Text)));
end;

procedure TForm1.Button3Click(Sender: TObject);
//动态使用外部函数实例--动态调用
var
H: HWnd;
p,p2: function(p1,p2:integer):integer
stdcall;
begin
H := LoadLibrary(PChar('P_dllexampl.dll'));
p:=nil;
if H <> 0 then
begin
p := GetProcAddress(H, PChar('fun_add'));
p2 := GetProcAddress(H, PChar('fun_dec'));
if Assigned(p) then
begin
// a1:=p(1,2);
// a2:=p2(1,2);
edit4.Text:=inttostr(p(strtoint(edit1.Text),strtoint(edit2.Text)));
edit5.Text:=inttostr(p2(strtoint(edit1.Text),strtoint(edit2.Text)));
end;
end;

FreeLibrary(H);
end;

end.
 
建议看书,很多书上有例子,因为牵扯到至少三个单元(包括library单元),
可能在此说的篇幅较大.
其实,就像你说的并不难,只要动手做过一次,就有经验了.
 
阿乐,请发教程uranium_235@etang.com
先送50分!
 
已发过。
 
顶部