给你段代码参考,我最近也在搞这个,DLL加MDI子窗体,DLL部分的, library test_dll;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses SysUtils, Classes, Forms, Windows, ADODB, test_form1 in 'test_form1.pas' {Form1};type adoPI = ^TADOConnection; {$R *.res} var DLLApp: TApplication; function ShowForm_2(var App: TApplication; ParentForm: TForm; adopi1: adoPI): Boolean;export; stdcall; begin {获取调用窗体的Application,显而易见的功能是 能使你的窗体融合到调用程序中。通过它还能进行很多操作} Application:= App;//将DLL的Application转为App Form1:= TForm1.Create(Application);//创建子窗体,子窗体随着ParentForm存在、释放。 Form1.FormStyle:= fsMDIChild;//设置窗体模式 Form1.Show; form1.ADOTable1.Connection:=adopi1^; Form1.temp_str:=adopi1^.ConnectionString; end;{重写Dll入口函数,否则程序会出错} procedure DLLUnloadProc(Reason: Integer); register; begin {DLL取消调用时,发送DLL_PROCESS_DETACH消息,此时将DLL的Application返回为本身} if Reason = DLL_PROCESS_DETACH then Application:=DLLApp; end;exports showform_2;begin {在DLL入口预先储存DLL的Application} DLLApp:=Application; {DllProc:DLL入口函数指针。Delphi定义为 DllProc: TDLLProc;} {在此指向我们自己定义的函数} DLLProc := @DLLUnloadProc; end.
试试:procedure ShowMainForm(hnd: THandle; AParent: TCustomControl);
最重要的一点是:还需要重写dll入口函数。
library test_dll;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Windows,
ADODB,
test_form1 in 'test_form1.pas' {Form1};type
adoPI = ^TADOConnection;
{$R *.res}
var DLLApp: TApplication;
function ShowForm_2(var App: TApplication; ParentForm: TForm; adopi1: adoPI): Boolean;export; stdcall;
begin
{获取调用窗体的Application,显而易见的功能是 能使你的窗体融合到调用程序中。通过它还能进行很多操作}
Application:= App;//将DLL的Application转为App
Form1:= TForm1.Create(Application);//创建子窗体,子窗体随着ParentForm存在、释放。
Form1.FormStyle:= fsMDIChild;//设置窗体模式
Form1.Show;
form1.ADOTable1.Connection:=adopi1^;
Form1.temp_str:=adopi1^.ConnectionString;
end;{重写Dll入口函数,否则程序会出错}
procedure DLLUnloadProc(Reason: Integer); register;
begin
{DLL取消调用时,发送DLL_PROCESS_DETACH消息,此时将DLL的Application返回为本身}
if Reason = DLL_PROCESS_DETACH then Application:=DLLApp;
end;exports
showform_2;begin
{在DLL入口预先储存DLL的Application}
DLLApp:=Application;
{DllProc:DLL入口函数指针。Delphi定义为 DllProc: TDLLProc;}
{在此指向我们自己定义的函数}
DLLProc := @DLLUnloadProc;
end.
而是采用MDI的方式。
但要注意,调用的主界面是FormStyle为fsMDIForm。因为默认值一般是fsNormal。
因为Dll和Exe之间的地址空间并不共享,比如某甲身上的口袋并不是某乙的口袋