这个dll调用该怎么释放?
我写了一个dll,封装了几个窗口,窗口之间有调度操作,
应用部分:
- Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);typeTFunc=procedure;stdcall;varTh:Thandle;Tf:TFunc;beginTh:=LoadLibrary('ReStore.dll'); {装载DLL}if Th>0then begin try @Tf:=GetProcAddress(Th,PChar('createform')); if @Tf<>nil then tf else ShowMessage('createform函数没有找到'); finally FreeLibrary(Th); end; endelse ShowMessage('ReStore.dll没有找到');end;DLL定义:
- Delphi(Pascal) code
uses SysUtils, Classes, AdminRestoreDBSelectDB in 'AdminRestoreDBSelectDB.pas' {AdminRestoreDBSelectDBForm}, AdminDeleteDB in 'AdminDeleteDB.pas' {AdminDeleteDBForm}, AdminRestoreDB in 'AdminRestoreDB.pas' {AdminRestoreDBForm}; procedure createform;stdcall; begin AdminRestoreDBForm:=TAdminRestoreDBForm.Create(nil); AdminRestoreDBForm.ShowModal; end;{$R *.res}exports createform;beginend.因为调用dll后马上释放了dll,所以关闭dll的打开窗口后会抛出错误,但如果不在try...finally里释放dll,又该怎么执行FreeLibrary()呢?
[解决办法]
DLL里建FORM时,使用模式显示,即Showmodal;