delphi DLL问题 delphi中一个值得大家来考虑的DLL问题
人气:0想了解delphi中一个值得大家来考虑的DLL问题的相关内容吗,在本文为您仔细讲解delphi DLL问题的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:delphi,DLL,下面大家一起来学习吧。
以下是我的原代码:
==========================================================================================
DPR 单元代码
program Mdiform;
uses
Forms,
UMdiform in ´UMdiform.pas´ {Mainform},
UDM in ´UDM.pas´ {GlobalDM: TDataModule},
UFun in ´UFun.pas´;
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainform, Mainform);
Application.Run;
end.
===============================================================================================
主窗体代码:
unit UMdiform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Udm,StdCtrls;
type
TMainform = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
MyHandle:HWND;
{ Public declarations }
end;
var
Mainform: TMainform;
type
T_ShowTestMng=function (var adm:TMainform) : Boolean; StdCall;
implementation
{$R *.dfm}
procedure TMainform.Button1Click(Sender: TObject);
var
Lib_ :THandle;
_ShowTestMng :T_ShowTestMng;
begin
Lib_:=LoadLibrary(pchar(´MdiChild.dll´));
try
@_ShowTestMng:=GetProcAddress(Lib_,´_ShowTestMng´);
if not(@_ShowTestMng=nil) then
_ShowTestMng(Mainform);
finally
FreeLibrary(Lib_);
end;
end;
procedure TMainform.FormCreate(Sender: TObject);
begin
MyHandle:=Application.Handle;
end;
end.
==============================================================================================
子窗体DLL代码:
library MdiChild;
uses
ShareMem,
UMdiform, //此单元为父窗体单元,在顶目设置中我已经设置了搜索此单元在路径。
Forms,
SysUtils,
Classes,
UChild in ´UChild.pas´ {FrmChild};//FrmChild子窗体的FormStyle属性为FsMDIChild
{$R *.res}
function _ShowTestMng(var adm:TMainform) : Boolean; StdCall;
begin
result:=true;
Application.Handle:=adm.MyHandle;
Application.CreateForm(TFrmChild,FrmChild); //程序就出错在此:出错原因是:Cannot create form. No MDI Forms are currently active.
FrmChild.Show;
end;
exports
_ShowTestMng;
end.
加载全部内容