delphi 调用动态窗体DLL 出错问题 急。。在线等
调用DLL
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;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.
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