|
两种方法,一种为下面的代码部分,另一种在后面的附件中:
程序的代码:
- unit MainUnit;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, dynlibs;
- type
- { TForm1 }
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- UI: TLibHandle;
- ShowDLLForm: procedure; stdCall;
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- UI:=LoadLibrary('UI.dll');
- Pointer(ShowDLLForm):=GetProcAddress(UI, 'ShowDLLForm');
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- ShowDLLForm;
- end;
- end.
复制代码 DLL的代码:- library Userinterface;
- {$mode objfpc}{$H+}
- uses
- Classes, Interfaces, UnitDllForm
- { you can add units after this };
- {$R *.res}
- procedure ShowDLLForm; stdCall;
- begin
- Form1.Show;
- end;
- // Exports
- exports
- ShowDLLForm; stdCall:
- begin
- end.
复制代码 下面是个例子:
或直接用网盘下载:
下载地址 |
|