Home > Back-end >  DLL call, window display. But the main program closed, form the object how to release?
DLL call, window display. But the main program closed, form the object how to release?

Time:09-28

DLL interface function
The function LoadDllForm (AHandle AParent: HWnd) : TForm; Stdcall;
The begin
Application. Handle:=AHandle;
Application CreateForm (TfrmTest frmTest);
Try
FrmTest. ParentWindow:=AParent;
FrmTest. BorderStyle:=bsNone;
FrmTest. WindowState:=wsMaximized;

FrmTest. Show;

Result:=frmTest;
Except,
Result:=nil;
FrmTest. Free;
end;
end;

The main program using static call
DLL interface function declaration
The function LoadDllForm (AHandle AParent: HWnd) : TForm; Stdcall; External 'TestDLL. DLL'

The main program called
FrmDllForm:=LoadDllForm (Application. Handle, Panel1. Handle);

Main program according to normal, but the program is closed, how can I release frmTest object? Direct frmDllForm. Free just frmTest logout function of the parent object

CodePudding user response:

Create, where you generally follow the release principle, you can create a window Handle to keep up, and then write a method, Export, Handle, and then you find the corresponding internal form, and then the DLL released, that is to say, you LoadDllForm returns a Handle, and then write a FreeDLLForm, parameters for LoadDllForm the returned Handle, and then to deal with by yourself

CodePudding user response:

There is a more troublesome thing, know handle, how to obtain the object instances? Can help solve?

CodePudding user response:


Sorry, you DLL you save the line ah, using a Hash stored on, and then according to the object handle to find your saved release!

CodePudding user response:

Close the program through the handle to release,

CodePudding user response:

Can give simple code

CodePudding user response:

 
//pseudo code
Var
The List: TStringList;

The function LoadDllForm (AHandle AParent: HWnd) : THandle; Stdcall;
The begin
Application. Handle:=AHandle;
Application CreateForm (TfrmTest frmTest);
Try
FrmTest. ParentWindow:=AParent;
FrmTest. BorderStyle:=bsNone;
FrmTest. WindowState:=wsMaximized;

FrmTest. Show;

Result:=frmTest. Handle;
If the list=nil then
The begin
List:=TStringList. Create;
end;
List. AddObject (inttostr (Result), frmtest);
Except,
Result:=nil;
FrmTest. Free;
end;
end;

Procedure LoadDllForm (AHandle: HWnd); Stdcall;
The begin
If the list & lt;> Nil then
The begin
Independence idx:=list. Indexof (inttostr (AHandle));
If independence idx & lt;> 1 then
List. The Objects/independence idx. Free;
end;
end;


All said very understand, also don't want to give the code,,, they need to think about more,

CodePudding user response:

Speak a little bit rogue main program have closed process is dead is automatically released not virgo you can regardless of the ha ha

CodePudding user response:

Procedure TForm. FormClose (Sender: TObject; Var Action: TCloseAction);
The begin
Action:=cafree;
FmPrint:=nil;
end;

CodePudding user response:

Please use the eighth floor
  • Related