delphi 调用动态窗体DLL 出错问题 急。。在线等
调用DLL
- Delphi(Pascal) code
TNoticeDLLCreate = function(App: TApplication; Scr: TScreen; InterfaceDate : TInterfaceDate): Boolean;stdcall; //公共信息DLLvar DLLHandle : THandle; DLLForm: TNoticeDLLCreate;begin try GetInterfaceDate; Self.Enabled := False; DLLHandle := LoadLibrary('NoticeDLL.dll'); if DLLHandle <> 0 then begin @DLLForm := GetProcAddress(DLLHandle, 'NoticeDLLCreate'); if Assigned(DLLForm) then begin DLLForm(Application, Screen,InterfaceDate); end; FreeLibrary(DLLHandle); end; Self.Enabled := True; finally Application.MainForm.Visible := True; end;DLL单元
- Delphi(Pascal) code
var DLLAPP : TApplication; DLLScr: TScreen; function NoticeDLLCreate(App: TApplication; Scr: TScreen; InterfaceDate : TInterfaceDate) : Boolean; stdcall; begin result := False; CoInitialize(nil); Application := aapp; Screen := Scr; try frmNotice := TfrmNotice.Create(nil); frmNotice.Showmodal; finally CoUninitialize; end; result := True; end; procedure ExitDLL(Reason: Integer); begin if (Reason = DLL_PROCESS_DETACH) or (Reason = DLL_THREAD_DETACH) then begin Application := DLLApp; Screen := DLLScr; end; end; exports NoticeDLLCreate;begin DLLAPP := Application; DLLScr := Screen; DllProc := @ExitDLL;end.
如果调用其中的函数,则freelibrary(程序最终退出时出现cpu窗口。说什么存取异常。屏蔽掉freelibrary就不会有这个问题)
但dll中只是简单的数据库操作,没有创建什么东西
不操作数据库的话好像就没有异常了,但内存泄漏
[解决办法]
既然没有释放,还是推荐你写个释放函数,以免创建多次执行,或者至少创建前判断form是否已经创建
另外你的代码不全,如果InterfaceDate是个接口,可以先把这个参数去掉看看
[解决办法]
单位强化管理,米有任何第三方软件,否则工资20%就捐了
[解决办法]
1.Showmodal有free掉
2.操作数据库代在那?
[解决办法]
- Delphi(Pascal) code
var h: Cardinal;begin result := False; CoInitialize(nil); h := Application.Handle; Application.Handle := App.Handle; try frmNotice := TfrmNotice.Create(nil); frmNotice.Showmodal; FreeAndNil(frmNotice); Application.Handle := h; finally CoUninitialize; end; result := True;end;
[解决办法]
内存问题,查内存Free