delphi中一个值得大家来考虑的DLL问题

时间:2021-05-20


以下是我的原代码:
==========================================================================================
DPR单元代码
programMdiform;
uses
Forms,
UMdiformin´UMdiform.pas´{Mainform},
UDMin´UDM.pas´{GlobalDM:TDataModule},
UFunin´UFun.pas´;
{$R*.res}
begin
Application.Initialize;
Application.CreateForm(TMainform,Mainform);
Application.Run;
end.
===============================================================================================
主窗体代码:
unitUMdiform;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,Udm,StdCtrls;
type

TMainform=class(TForm)
Button1:TButton;
procedureButton1Click(Sender:TObject);
procedureFormCreate(Sender:TObject);
private
{Privatedeclarations}
public
MyHandle:HWND;
{Publicdeclarations}
end;
var
Mainform:TMainform;
type
T_ShowTestMng=function(varadm:TMainform):Boolean;StdCall;
implementation
{$R*.dfm}
procedureTMainform.Button1Click(Sender:TObject);
var
Lib_:THandle;
_ShowTestMng:T_ShowTestMng;
begin
Lib_:=LoadLibrary(pchar(´MdiChild.dll´));
try
@_ShowTestMng:=GetProcAddress(Lib_,´_ShowTestMng´);
ifnot(@_ShowTestMng=nil)then
_ShowTestMng(Mainform);
finally
FreeLibrary(Lib_);
end;
end;
procedureTMainform.FormCreate(Sender:TObject);
begin
MyHandle:=Application.Handle;
end;
end.
==============================================================================================
子窗体DLL代码:
libraryMdiChild;
uses
ShareMem,
UMdiform,//此单元为父窗体单元,在顶目设置中我已经设置了搜索此单元在路径。
Forms,
SysUtils,
Classes,
UChildin´UChild.pas´{FrmChild};//FrmChild子窗体的FormStyle属性为FsMDIChild
{$R*.res}
function_ShowTestMng(varadm:TMainform):Boolean;StdCall;
begin
result:=true;
Application.Handle:=adm.MyHandle;
Application.CreateForm(TFrmChild,FrmChild);//程序就出错在此:出错原因是:Cannotcreateform.NoMDIFormsarecurrentlyactive.
FrmChild.Show;
end;
exports
_ShowTestMng;
end.

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章