Dll 问题:(100分)

Z

zhczm

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了两个独立的Dll窗体A,B
我要分别同时动态载入两个动态建立的页,但是有如下问题:
1,不能同时载入
2 ,必须把上一个句柄完全卸载,才可以载入下一个Dll窗体
3 在Dll窗体A不能动态载入Dll窗体B
我的载入程序:
代码:
private
TT : TrzTabSheet;
TP : TrzPageControl;
hd: THandle;
Dll_hd: THandle;
TFrm:TFormClass;
frm:TForm;
{ Private declarations }
public
{ Public declarations }
end;


procedure Tf_auto.RzButton2Click(Sender: TObject);
type TGetDllForm_user=function():TFormClass;stdcall;
var fm:TGetDllForm_user;
tf:tfarproc;
i:integer;
s,bs:string;
begin
s:='user1';
if tp=nil then
begin
tp:= TrzPageControl.Create(self);
tp.Parent :=panel1;
tp.Align:=alclient;
tp.TabOrientation:=toBottom;
end;
bs:='A';
if tp.PageCount>0 then
for i:=0 to tp.PageCount-1do
begin
if trim(tp.Pages.Caption)=s then
begin
tp.ActivePageIndex:=i;
bs:='';
break;
end;
end;
if bs='A' then
begin
tt:= TrzTabSheet.Create(tp);
tt.Parent:=tp;
//tt.Visible := True;
tt.Caption :=s;
tt.PageControl :=tp;
tt.Align:=alclient;
tp.ActivePageIndex:=tt.PageIndex;
Dll_hd :=LoadLibrary('userdll1.dll');
try
tf:=GetProcAddress(Dll_hd, 'GetDllForm_user');
if tf = nil then
Abort;
fm:=TGetDllForm_user(tf);
Tfrm:=fm();
frm:=tfrm.Create(tt);
frm.Parent:=tt;
frm.Align:=alclient;
frm.Show;
except raise;
//finally freelibrary(hd);
//
end;
end;
end;

procedure Tf_auto.RzButton3Click(Sender: TObject);
type TGetDllForm_user=function():TFormClass;stdcall;
var fm:TGetDllForm_user;
tf:tfarproc;
i:integer;
s,bs:string;
begin
s:='user';
if tp=nil then
begin
tp:= TrzPageControl.Create(self);
tp.Parent :=panel1;
tp.Align:=alclient;
tp.TabOrientation:=toBottom;
end;
bs:='A';
if tp.PageCount>0 then
for i:=0 to tp.PageCount-1do
begin
if trim(tp.Pages.Caption)=s then
begin
tp.ActivePageIndex:=i;
bs:='';
break;
end;
end;
if bs='A' then
begin
tt:= TrzTabSheet.Create(tp);
tt.Parent:=tp;
//tt.Visible := True;
tt.Caption :=s;
tt.PageControl :=tp;
tt.Align:=alclient;
tp.ActivePageIndex:=tt.PageIndex;
Dll_hd :=LoadLibrary('userdll.dll');
try
tf:=GetProcAddress(Dll_hd, 'GetDllForm_user');
if tf = nil then
Abort;
fm:=TGetDllForm_user(tf);
Tfrm:=fm();
frm:=tfrm.Create(tt);
frm.Parent:=tt;
frm.Align:=alclient;
frm.Show;
except raise;
//finally freelibrary(hd);
//
end;
end;
end;
 
Dll_hd :=LoadLibrary('userdll.dll');
try
tf:=GetProcAddress(Dll_hd, 'GetDllForm_user');
干嘛要装载2次,直接判断Dll_hd是否有效,有效就直接调GetProcAddress就可以了
 
你的DLL档采用的是有模式,所以必须第一个窗口释放后, 才能执行第二个DLL!
(具体的可以搜一下关于模式窗体与无模式窗体的相关说明)
解决此问题二个方法:
1. 建立一个线程组,由每个组保存一个线程, 每个线程负责处理调用一个DLL;
(简单一点就直接建二个线程TThread)
2. 相对复杂一点, 难于表达!
 
Dll_hd :=LoadLibrary('userdll.dll');
try
tf:=GetProcAddress(Dll_hd, 'GetDllForm_user');
干嘛要装载2次,直接判断Dll_hd是否有效,有效就直接调GetProcAddress就可以了
我的是两个Dll文件阿 'userdll.dll' 'userdll1.dll'
 
你的DLL档采用的是有模式,所以必须第一个窗口释放后, 才能执行第二个DLL!
(具体的可以搜一下关于模式窗体与无模式窗体的相关说明)
解决此问题二个方法:
1. 建立一个线程组,由每个组保存一个线程, 每个线程负责处理调用一个DLL;
(简单一点就直接建二个线程TThread)
2. 相对复杂一点, 难于表达!

我都是无模 的打开的
 
我发给你了
 
接受答案了.
 
顶部