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

来源:互联网 发布:淘宝旧书店 编辑:程序博客网 时间:2024/05/29 16:05
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

在MDI窗体类型的编程中,主窗体(fsMDIForm)怎样调用子窗体(fsMDIChild,此子窗体为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.

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击