mydll.dpr:
-------------------------------
library MyDll;
//定义DLL中的函数MyFunc
function MyFunc(a, b: integer): integer; stdcall;
begin
Result := a + b;
end;
//引出函数名
exports
MyFunc;
end.
usemydll.dpr
-----------------------------------
program UseMyDll;
uses
Forms,
MainFrm in 'MainFrm.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
mainfrm.pas
---------------------------------
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
//外部声明MyFunc()函数
function MyFunc(a, b: integer): integer; stdcall external 'MyDll.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
try
Edit3.Text := IntToStr(MyFunc(StrToInt(Edit1.Text), StrToInt(Edit2.Text)));
finally
end;
end;
end.