I don't know if this will address all the issues (save freeing the form, I would expose functions to do anything external involving the dll form), but this should give a good start:
library testdll;
uses dllunit in 'dllunit.pas' {Form1}, windows;
procedure callform(ParentForm: HWnd);
// simple test, resource management is necessary on the form.
var
dllform: TForm1;
begin
dllform := TForm1.Create(nil);
dllform.Show;
Windows.SetParent(dllform.Handle, ParentForm);
end;
exports
callform;
end.
program mainprogram;
procedure callform(ParentHandle: THandle); external 'testdll.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
callform(Panel1.Handle);
end;
Like was said, there might be other issues once you start adding features to the dll form, but (for me) it's putting the form designed in dllunit.pas into the main form's project with Panel1 as a parent and is operating as expected. But like was said, this was just intended as a start.