以下是比较三个数最大值的一个DLL,如何用动态调用?
library max;
uses
SysUtils,
Classes;
{$R *.res}
function max1(a,b,c:integer):integer;stdcall;
var t:integer;
begin
if a>b then t:=a
else t:=b;
if t>c then result:=t
else result:=c;
end;
exports
max1;
begin
end.主程序有四个框,Edit1,Edit2,Edit3为输入框,Edit4为输出框,一个BUTTON1按钮,如何操作,麻烦贴出全部代码,新手还不是太理解原理,谢谢!
library max;
uses
SysUtils,
Classes;
{$R *.res}
function max1(a,b,c:integer):integer;stdcall;
var t:integer;
begin
if a>b then t:=a
else t:=b;
if t>c then result:=t
else result:=c;
end;
exports
max1;
begin
end.主程序有四个框,Edit1,Edit2,Edit3为输入框,Edit4为输出框,一个BUTTON1按钮,如何操作,麻烦贴出全部代码,新手还不是太理解原理,谢谢!
解决方案 »
- 寻高级程序员,兼职高酬
- 软件公司面试试题,好难,紧急求助!!!
- 怎样将dbgrid的内容打印呀?
- 很简单的问题,分不够了再加:Delphi如何实现向指定的IP或者计算机名地址发送消息,象Net Send 命令一样
- 请问个人给一个公司做项目应该如何签协议保证个人的利益
- 300分请教:求一公钥/私钥的加密算法
- IdTCPServer IdTCPClient 双向接发消息已经实现 但碰到了一个很奇怪的问题
- !!!!!!有谁知道Delphi6.0开发人员指南英文版什么地方有下载,最好是中文的。高分求答。
- 如何用程序创建一个数据库文件?
- 我下了一个软件不知道该如何解压!
- 在D2010中安装了组件,为什么在工具面板中找不到?
- delphi 写的ocx文件 放到asp.net里面是灰色的
procedure TForm1.Button1Click(Sender: TObject);
type
TIntFunc=function(a,b,c:integer):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
begin
Th:=LoadLibrary(’max.dll’); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar(’max1’));
if Tp<>nil
then begin
Tf:=TIntFunc(Tp);
Edit4.Text:=IntToStr(Tf(strtoint(Edit1.Text),strtoint(Edit2.Text),strtoint(Edit3.Text))); {调用max1函数}
end
else
ShowMessage(’max1函数没有找到’);
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage(’max.dll没有找到’);
end;
在调用的里面加入声明
function max1(a,b,c:integer):integer;stdcall; external 'xxxx.dll'然后就可以直接使用函数了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function max1(a,b,c:integer):integer;stdcall;external 'max1.dll' name 'max1';
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c:integer;
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
edit4.Text:=inttostr(max1(a,b,c));
end;end.