Redberet大侠,我的Dll调用如下
procedure TMainForm.FormCreate(Sender: TObject);
var
Handle: THandle;
AppHandle:THandle;
passwd:function(AppWnd:LongInt;table:TClientDataSet):boolean
begin
mainform.Visible:=false;
Handle := LoadLibrary('Extra/Extra.dll');
if Handle <> 0 then
begin
@passwd := GetProcAddress(Handle, 'login');
if @passwd <> nil then
begin
AppHandle:=Application.Handle;
if passwd(application.handle,(datamodule1.passwdtable)) then
begin
mainform.Visible:=true;
try
Application.Handle:=AppHandle;
FreeLibrary(Handle);
except
showmessage('library unloaded failed!');
end;
end
else
begin
try
FreeLibrary(Handle);
Application.Handle:=AppHandle;
except
showmessage('library unloaded failed!');
end;
free;
end;
end;
end
else showmessage('cannot load library');
end;
这样将Handle保存并返回应该可以吧,可不管加不加如下两行都一样
AppHandle:=Application.Handle;
Application.Handle:=AppHandle;
有趣的是,如果去掉Freelibrary(Handle)那么问题就解决了,而且在以后的程序代码中
再调用动态Dll也不会出现任何问题,可加上这一句以后每一次调用Dll中的Form都会隐藏
主窗体,我是在nt workstation 4。0 Delphi 5下调试的,谢谢帮忙诊治