关于DLL里有窗体的有关问题
关于DLL里有窗体的问题
在DLL中
我想这样调用。
function zjpfm:TForm;stdcall;external 'Win32\Debug\DllMain.dll';
……
procedure TForm1.FormCreate(Sender: TObject);
var
cc:TForm;
begin
cc:=TForm.Create(Application);
cc:=zjpFm;
//cc:=TForm.Create(Application);
cc.Parent:=Self
cc.Visible:=True;
end;
可是这样用有问题。会有异常出现,还有就是关不掉cc
------解决方案--------------------
http://blog.****.net/zhenghui1/article/details/5940510
------解决方案--------------------
记得在dll函数中一定要加入application的句柄
在DLL中
- Delphi(Pascal) code
library DllMain; …… function fm:TForm;stdcall; begin fmDllMain := TfmDllMain.Create (nil); Result:=fmDllMain; {procedure TForm1.Button1Click(Sender: TObject); VAR AA:TForm; begin AA:=zjpFm; AA.Parent:=nil; AA.ShowModal; FreeAndNil(AA); end;} end; exports fm name 'zjpfm'; begin end.
我想这样调用。
function zjpfm:TForm;stdcall;external 'Win32\Debug\DllMain.dll';
……
procedure TForm1.FormCreate(Sender: TObject);
var
cc:TForm;
begin
cc:=TForm.Create(Application);
cc:=zjpFm;
//cc:=TForm.Create(Application);
cc.Parent:=Self
cc.Visible:=True;
end;
可是这样用有问题。会有异常出现,还有就是关不掉cc
------解决方案--------------------
http://blog.****.net/zhenghui1/article/details/5940510
------解决方案--------------------
记得在dll函数中一定要加入application的句柄
- Delphi(Pascal) code
function ABC(AppHandle:HWND; Btns: LongInt): LongInt; export; stdcall; begin Application.Handle:=AppHandle; IsGetButtonList := True; frmChild:=TfrmABC.Create(Application); try frmChild.GetChildFormButton(Btns); finally FreeAndNil(frmChild); end; end;
------解决方案--------------------
屏蔽cc.Parent:=Self
使用
windows.SetParent(cc.Handle, Handle);
------解决方案--------------------
dll 代码
function fm: TForm; stdcall;
begin
Form2 := TForm2.Create(nil);
Result := Form2;
end;
exports fm name 'zjpfm';
begin
end.
窗体代码
var
cc: TForm;
begin
cc:=TForm.Create(nil);
cc := zjpFm;
windows.SetParent(cc.Handle, Handle);
cc.Visible := True;
end;
------解决方案--------------------
这样写——————————————————————————
function abc: TForm; stdcall;
begin
Result := TForm1.Create(Application);
end;
------解决方案--------------------
dll窗体融合主程序窗体吗?
cc:=zjpFm;
cc.ParentWindow:=Self.handle;
cc.align:=alClient;
cc.icon.handle:=Application.icon.handle;
cc.show;
------解决方案--------------------
另外,用主程序的application.handle替换dll的application.handle
------解决方案--------------------
引用方式不对,或者DLL中的接口不规范
------解决方案--------------------
这样写吧
procedure VS_Createform(App:THandle);stdcall;
begin
Application.Handle := App;
if fmDllMain =nil then
form1:=TfmDllMain.Create(application);
form1.Position := poDesktopCenter;
FSisonline := false;
form1.show;
end;
------解决方案--------------------
FSisonline := false;
这句不要,这是我程序里面写的