主窗体调用DLL中的子窗体(100分)

C

cly402

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎么在主窗体中调用DLL中的子窗体?
我的一个主程序:
procedure TFrmMain.FormKeyPress(Sender: TObject; var Key: Char);
var
TIntFunc:function(AHandle:THandle;ACaption:string):LongInt;stdcall;
uRet:integer;
begin
Case key of
'1':
begin
Th:=LoadLibrary('ggxx.dll'); {装载DLL}
if Th>0 then
try
@TIntFunc:=GetProcAddress(Th,PChar('ShowForm'));
if Assigned(TIntFunc) then
begin
uRet:=TIntFunc(Application.Handle,IsCardIn);
end
else
ShowMessage('ShowForm函数没有找到');
finally
FreeLibrary(Th);
end;
end;
end;
end;
dll里的程序:
function ShowForm(ParentHandle:THandle;ACaption:String):LongInt;stdcall;
begin
Init_PubVar;
Application.handle :=Parenthandle;
if Not Assigned(FrmMainMenu) then
FrmMainMenu:=TFrmMainMenu.Create(Application);
Try
FrmMainMenu.Show;
Result:=LongInt(FrmMainMenu);
except
Result:=-1;
end;
end;

procedure UnLoadForm;StdCall;
var
i:integer;
begin
for i:=0 to Screen.FormCount -1 do
begin
Screen.Forms.Close;
end;
end;
为什么我在主窗体中一调用dll,子窗体不出现,而主窗体在屏幕上也没了?请求高手帮忙。

 
你的邮箱?
 
我的邮箱为lanlan7737@sina.com,
请问不要try。。。finally这句,dll能不能有别的释放方法?
 
怎么没人帮我阿,
第一次调用dll没问题,等退出到主菜单在按1进dll的时候,桌面什么都没了。
不用finally卸有没有问题阿?
 
此问题我已经解决?要怎么取消给分阿?
 
cly402:
能否给个例子看看
 
没办法取消的,呵呵。。
 
把分分了吧,取消不了的
 
没有看到你完整的程序,但看代码还是有点问题的。
1.在程序的interface中定义DLL接口,而你的在函数中定义;
2.在DLL函数中function ShowForm(ParentHandle:THandle;ACaption:String):LongInt;stdcall;
要定义Form:TForm,在DLL中虽然不可以构建FORM,但要继承它的方法,如果不继承也可以,你
应该在参数中加上一个参数(ParentHandle:THandle;ACaption:String;var form:tform1),在
宿主程序中传入tform1;
3.你在窗体中有FrmMainMenu,应该在Form类中定义FrmMainMenu;
4.for i:=0 to Screen.FormCount -1 do
那不是将自己的主窗体也包括进来了吗?
只是从代码中分析的,不知道正确不正确。你可以先建立一个窗体单元,然后再改动一下,
作为DLL就可以了!
 
问题出在这里:
FrmMainMenu.Show
之后你就FreeLibrary(Th);子窗体当然看不见。
建议改成ShowModal或者静态调用。
 
主窗体不是没有,而是在DLL生成的窗体后面!
 
好了,散分了,谢谢各位对我的关心,发者有分,以后还请各位多多关照。
 
好了,散分了,谢谢各位对我的关心,发者有分,以后还请各位多多关照。
 
顶部