特别奇怪的Dll释放问题,FreeLibrary就会出错.......

wolf2005 2003-08-07 05:22:32
dll单元
uses
SysUtils,
Classes;
ndll in 'ndll.pas';
{$R *.res}
exports
x;
begin
end.

unit ndll;
interface
uses
SysUtils, Classes, Dialogs;
function x(s:string):string;stdcall;
implementation
function x(s:string):string;
begin
Result:='ok';
end;
end.
调用单元
unit untmain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TX = function (s:string):string;stdcall;
TForm1 = class(TForm)
Button3: TButton;
procedure Button3Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
var
xx:TX; Lib: THandle;
begin
Lib := SafeLoadLibrary('dll.dll');
try
if Lib <> 0 then
@xx := GetProcAddress(Lib, 'x');
if not (@xx = nil) then
if xx('a') = 'ok' then
showmessage('ok');
finally
FreeLibrary(Lib); // 为什么为释放不掉,一释放就会出现地址访问错误
end;
end;
end.
...全文
105 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧