静态/动态调用dll封装窗体(模态/非模态)
看到有网友需要这样的例子,所以写了一个.
有不对或不合理的地方请跟帖指导.
delph XE下测试通过.
Dll项目文件
unit Unit13;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm13 = class(TForm) btn1: TButton; btn2: TButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form13: TForm13; function MyForm(H: THandle) : THandle; stdcall;implementationfunction MyForm; external 'Project10.dll' name 'GetForm';{$R *.dfm}//动态调用 模态窗口procedure TForm13.btn1Click(Sender: TObject);type TGetForm = function (H: THandle) : Integer; cdecl;var DllForm : TGetForm; DllHandle : THandle; nn : integer;begin DllHandle := LoadLibrary(PChar('Project10.dll')); try if DllHandle <> 0 then begin DllForm := GetProcAddress(DllHandle, 'EDebtMoney'); nn := DllForm(Application.Handle) ; self.Caption := inttostr(nn); end; finally FreeLibrary(DllHandle); end;end;//静态调用 非模态窗口procedure TForm13.btn2Click(Sender: TObject);var DllHandle : THandle;begin DllHandle := MyForm(Application.Handle);end;end.