library ChildDll;{ 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 Windows, SysUtils, Classes, Forms, Child in 'Child.pas' {Form1};var DllApp : THandle; {$R *.RES}procedure MyDLLProc(Reason: Integer); begin // DLL is unloading. Restore the Application pointer. if Reason = DLL_PROCESS_DETACH then begin if DllApp<>0 then Application.Handle := DllApp; end; end;procedure CreateChildForm(MainApp:THandle);stdcall;export; var Child : TForm1; begin if not DllApp<>0 then begin DllApp := Application.Handle; Application.Handle := MainApp; end; Child := nil; try Child := TForm1.Create(Application); Child.Show(); except Child.Free(); end; end;exports CreateChildForm;begin DLLProc := @MyDLLProc; end.
to: liang_z(千山一刀之忍者神龟) 在关闭Dll子窗体Form1时,是不是和关闭一般的MDI子窗体一样啊?
然后在onclose中FreeDll吧
所以不用Free DLL的句柄。
不知道你们是如何控制的能不能贴段代码出来看看.
StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns,
ActnList, ToolWin, ImgList;type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileCloseItem: TMenuItem;
Window1: TMenuItem;
Help1: TMenuItem;
N1: TMenuItem;
FileExitItem: TMenuItem;
WindowCascadeItem: TMenuItem;
WindowTileItem: TMenuItem;
WindowArrangeItem: TMenuItem;
HelpAboutItem: TMenuItem;
OpenDialog: TOpenDialog;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
Edit1: TMenuItem;
CutItem: TMenuItem;
CopyItem: TMenuItem;
PasteItem: TMenuItem;
WindowMinimizeItem: TMenuItem;
StatusBar: TStatusBar;
ActionList1: TActionList;
EditCut1: TEditCut;
EditCopy1: TEditCopy;
EditPaste1: TEditPaste;
FileNew1: TAction;
FileSave1: TAction;
FileExit1: TAction;
FileOpen1: TAction;
FileSaveAs1: TAction;
WindowCascade1: TWindowCascade;
WindowTileHorizontal1: TWindowTileHorizontal;
WindowArrangeAll1: TWindowArrange;
WindowMinimizeAll1: TWindowMinimizeAll;
HelpAbout1: TAction;
FileClose1: TWindowClose;
WindowTileVertical1: TWindowTileVertical;
WindowTileItem2: TMenuItem;
ToolBar2: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton9: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
ImageList1: TImageList;
procedure FileNew1Execute(Sender: TObject);
procedure FileOpen1Execute(Sender: TObject);
procedure HelpAbout1Execute(Sender: TObject);
procedure FileExit1Execute(Sender: TObject);
private
{ Private declarations }
procedure CreateMDIChild(const Name: string);
public
{ Public declarations }
end;var
MainForm: TMainForm;//在这儿定义:
procedure CreateChildForm(MainApp:THandle);stdcall; external 'ChildDll.dll';implementation{$R *.DFM}uses About;procedure TMainForm.CreateMDIChild(const Name: string);
var
H: HWnd;
iMy: procedure(MainApp:THandle);stdcall;
begin
{ create a new MDI child window }
CreateChildForm(Application.Handle);
end;procedure TMainForm.FileNew1Execute(Sender: TObject);
begin
CreateMDIChild('NONAME' + IntToStr(MDIChildCount + 1));
end;procedure TMainForm.FileOpen1Execute(Sender: TObject);
begin
if OpenDialog.Execute then
CreateMDIChild(OpenDialog.FileName);
end;procedure TMainForm.HelpAbout1Execute(Sender: TObject);
begin
AboutBox.ShowModal;
end;procedure TMainForm.FileExit1Execute(Sender: TObject);
begin
Close;
end;end.
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
Windows,
SysUtils,
Classes,
Forms,
Child in 'Child.pas' {Form1};var
DllApp : THandle;
{$R *.RES}procedure MyDLLProc(Reason: Integer);
begin
// DLL is unloading. Restore the Application pointer.
if Reason = DLL_PROCESS_DETACH then
begin
if DllApp<>0 then
Application.Handle := DllApp;
end;
end;procedure CreateChildForm(MainApp:THandle);stdcall;export;
var
Child : TForm1;
begin
if not DllApp<>0 then
begin
DllApp := Application.Handle;
Application.Handle := MainApp;
end; Child := nil;
try
Child := TForm1.Create(Application);
Child.Show();
except
Child.Free();
end;
end;exports
CreateChildForm;begin
DLLProc := @MyDLLProc;
end.
在关闭Dll子窗体Form1时,是不是和关闭一般的MDI子窗体一样啊?