我写了一个dll,封装了几个窗口,窗口之间有调度操作,
应用部分:procedure TForm1.Button1Click(Sender: TObject);
type
TFunc=procedure;stdcall;
var
Th:Thandle;
Tf:TFunc;
begin
Th:=LoadLibrary('ReStore.dll'); {装载DLL}
if Th>0
then begin
     try
       @Tf:=GetProcAddress(Th,PChar('createform'));
       if @Tf<>nil
       then tf
       else ShowMessage('createform函数没有找到');
     finally
      FreeLibrary(Th);
     end;
     end
else ShowMessage('ReStore.dll没有找到');
end;
DLL定义: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;
begin
end.
因为调用dll后马上释放了dll,所以关闭dll的打开窗口后会抛出错误,但如果不在try...finally里释放dll,又该怎么执行FreeLibrary()呢?