library test;
uses
System.SysUtils,
System.Classes;
{$R *.res}
function sum(x,y:double):double; stdcall; //stadCALL,表明,
//此类函数可在其它VB,VC 等调用
begin
Result:=x+y;
end;
funCtion Minus(x,y:DOUBLE):DOUBLE;STDCALL;
BEGIN
if X>Y THEN
RESULT:=X-Y
ELSE
RESULT:=Y-X;
END;
exports
sum,
minus;
begin
end.
按CTRL+F9编译;
以下是调用
unit Unit5;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils,
System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm5 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
Edit4: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
function sum(x,y:double):double; stdcall ;external 'test.dll';//'test.dll'不在同一个路径的话,要加引用路径;
function Minus(x,y:double):double; stdcall ;external 'test.dll';//'test.dll'不在同一个路径的话,要加引用路径;
implementation
{$R *.dfm}
procedure TForm5.Button1Click(Sender: TObject);
var
x,y:double;
begin
if (edit1.Text='') or (edit2.Text='') then exit;
x:=strtofloat(edit1.Text);
y:=strtofloat(edit2.Text);
edit3.Text:=floattostr(sum(x,y)); //相加
edit4.Text:=floattostr(Minus(x,y)); //相减
end;
end.