DLL 接口函数
function LoadDllForm(AHandle, AParent: HWnd): TForm; stdcall;
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;主程序采用静态调用
DLL接口函数申明
function LoadDllForm(AHandle, AParent: HWnd): TForm; stdcall; external 'TestDLL.dll'主程序调用
frmDllForm:= LoadDllForm(Application.Handle, Panel1.Handle);主程序显示都正常,可是程序关闭的时候,我怎么释放frmTest对象呢?直接frmDllForm.Free只是frmTest父对象的注销函数啊
function LoadDllForm(AHandle, AParent: HWnd): TForm; stdcall;
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;主程序采用静态调用
DLL接口函数申明
function LoadDllForm(AHandle, AParent: HWnd): TForm; stdcall; external 'TestDLL.dll'主程序调用
frmDllForm:= LoadDllForm(Application.Handle, Panel1.Handle);主程序显示都正常,可是程序关闭的时候,我怎么释放frmTest对象呢?直接frmDllForm.Free只是frmTest父对象的注销函数啊
囧,你DLL中自己保存一下就行了啊,用一个Hash保存一下就是了,然后根据句柄找到你保存的对象释放就行了!
//伪代码
var
List: TStringList;function LoadDllForm(AHandle, AParent: HWnd): THandle; stdcall;
begin
Application.Handle := AHandle;
Application.CreateForm(TfrmTest, frmTest);
try
frmTest.ParentWindow := AParent;
frmTest.BorderStyle := bsNone;
frmTest.WindowState := wsMaximized; frmTest.Show; Result := frmTest.Handle;
if list= nil then
begin
list := TStringList.create;
end;
list.AddObject(inttostr(Result),frmtest);
except
Result := nil;
frmTest.Free;
end;
end;procedure LoadDllForm(AHandle: HWnd); stdcall;
begin
if list <> nil then
begin
idx := list.indexof(inttostr(AHandle));
if idx <> -1 then
List.Objects[idx].free;
end;
end;
都说的很明白了,还非要给出代码自己需要多思考一下的说。
begin
action := cafree;
FmPrint := nil;
end;