欢迎来到代码驿站!

Delphi代码

当前位置:首页 > 软件编程 > Delphi代码

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

时间:2020-11-30 12:49:46|栏目:Delphi代码|点击:

以下是我的原代码:
==========================================================================================
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.

上一篇:Delphi实现木马文件传输代码实例

栏    目:Delphi代码

下一篇:Delphi 生成excel中饼图的实例代码

本文标题:delphi中一个值得大家来考虑的DLL问题

本文地址:http://www.codeinn.net/misctech/27764.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有