delphi技术用以下方法调用dll,可以调出一个窗体,但在释放时出现问题,不能释放dll,当关闭窗体时,下面红色部分报错,请教如何释放?
function LoadDll(DllPath, DllFunc: string): Boolean;
type
  TIntFunc = function(Apphd, Iconhd: THandle): Integer; stdcall;
var
  Th: THandle;
  Tf: TIntFunc;
  Tp: TFarProc;
begin
  result := true;
  Th := LoadLibrary(pchar(DllPath)); {装载DLL}
  if Th > 0 then
  try
    Tp := GetProcAddress(Th, pchar(DllFunc));
    if Tp <> nil then
    begin
      Tf := TIntFunc(Tp);
      Tf(application.Handle, application.Icon.Handle); {调用函数}//20100331
    end
    else application.MessageBox('函数没有找到', '提示');
  finally
    FreeLibrary(Th); {释放DLL}  end
  else application.MessageBox('DLL没有找到', '提示');
end;

解决方案 »

  1.   

    从你的程序来看,语法上是没有问题的,你确信单步跟踪到finally而不是出错后跳过去的?
    先把
    if Tp <> nil then
      begin
      Tf := TIntFunc(Tp);
      Tf(application.Handle, application.Icon.Handle); {调用函数}//20100331
      end
      else application.MessageBox('函数没有找到', '提示');部分注释掉看看
      

  2.   

    我的dll是一个窗体,当关闭后程序执行到FreeLibrary(Th); {释放DLL},就报错。
      

  3.   

    Tf(application.Handle, application.Icon.Handle); {调用函数}//20100331这个函数是正在被执行吗?如果是,那DLl正在被程序使用,肯定释放不了。
      

  4.   

    是什么错误,应该把错误贴出来,或者你在FreeLibrary后调用GetLastError,查看是什么原因