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;
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;
先把
if Tp <> nil then
begin
Tf := TIntFunc(Tp);
Tf(application.Handle, application.Icon.Handle); {调用函数}//20100331
end
else application.MessageBox('函数没有找到', '提示');部分注释掉看看