DLL窗体退出时出错__大家国庆快乐,帮我忙我也快乐!(38分)

  • 主题发起人 主题发起人 jozosoft
  • 开始时间 开始时间
J

jozosoft

Unregistered / Unconfirmed
GUEST, unregistred user!
主程序(是MDI主窗体):<br>...<br><br>var<br> &nbsp; function Load_FeeItemInfo(App: TApplication ):TForm; stdcall; external 'FeeMana.dll';<br>...<br><br>procedure TfmMain.N8Click(Sender: TObject);<br>var<br> &nbsp; fmbs_FeeItemInfo:TForm;<br>begin<br> &nbsp; &nbsp;// if (not Assigned(fmbs_FeeItemInfo)) or (fmbs_FeeItemInfo = Nil) then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fmbs_FeeItemInfo:= Load_FeeItemInfo( Application);<br> &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp;// &nbsp;fmbs_FeeItemInfo.Show; &nbsp;<br>end;<br><br><br>--------------------------------<br>Dll窗体(要作成MDI子窗体)<br>library FeeMana;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;Forms,<br> &nbsp;Windows,<br> &nbsp;Messages,<br> &nbsp;Dialogs,<br> &nbsp;ActiveX,<br> &nbsp;DB,<br> &nbsp;ADODB,<br> <br> &nbsp;FeeItemInfo in 'FeeItemInfo.pas' {fmbs_FeeItemInfo};<br><br>var<br> &nbsp;DLLApp: TApplication;<br> &nbsp;DLLScr: TScreen;<br><br> &nbsp;pubAdoConn:TAdoConnection;<br>{$R *.res}<br><br><br>procedure ExitDLL(Reason: Integer); register;<br>begin<br> &nbsp;showmessage('Dll退出!');<br> &nbsp;if(Reason = DLL_PROCESS_ATTACH) then<br> &nbsp;begin<br> &nbsp; &nbsp;CoInitialize(nil) ;<br> &nbsp;end ;<br><br> &nbsp;if Reason = DLL_PROCESS_DETACH then<br> &nbsp;begin<br> &nbsp; &nbsp;Screen:= DLLScr;<br> &nbsp; &nbsp;Application := DLLApp;<br> <br> &nbsp;end;<br>end;<br> <br>function Load_FeeItemInfo(App: TApplication ):TForm; stdcall;<br>var<br> &nbsp; i:integer;<br>begin<br> &nbsp;Application := App; &nbsp;//******请注意此行!!!!<br> &nbsp; // &nbsp; &nbsp;CoInitialize(nil) ;<br><br> &nbsp; showmessage('staart1');<br> &nbsp; if (not Assigned(fmbs_FeeItemInfo)) or &nbsp;(fmbs_FeeItemInfo = Nil) then<br> &nbsp; begin<br> <br> &nbsp; &nbsp; &nbsp; &nbsp;fmbs_FeeItemInfo:=Tfmbs_FeeItemInfo.Create(app );<br> &nbsp; &nbsp; &nbsp; &nbsp;fmbs_FeeItemInfo.FormStyle:=fsMDIChild;<br> &nbsp; &nbsp; &nbsp; &nbsp;fmbs_FeeItemInfo.Visible :=True;<br> <br> <br> &nbsp; end;<br> &nbsp; Result:=fmbs_FeeItemInfo;<br>end;<br> <br><br><br>exports<br> &nbsp;Load_FeeItemInfo;<br>begin<br> <br><br> &nbsp; DLLApp := Application;<br> &nbsp;DLLScr := Screen;<br> &nbsp;DLLProc := @ExitDLL; <br>end.<br><br>-----------<br>Dll子窗体的 OnClose中写有:<br>procedure Tfmbs_FeeItemInfo.FormClose(Sender: TObject;<br> &nbsp;var Action: TCloseAction);<br>begin<br> &nbsp;action:=cafree;<br> &nbsp;fmbs_FeeItemInfo:=Nil;<br>end;<br><br><br><br>************************************<br>错误:<br>1.如果去掉以下这行, 没有显示MDI子窗体,而是出错(退出主程序不会报内存出错):<br> &nbsp;<br> &nbsp;出错信息: Exception EInvalidOperation in module FeeMana.dll at 000549DF.<br><br> Application := App; &nbsp;//******请注意此行!!!!<br><br>2.如果加上Application := App;这一行, 能显示子窗体,但退出主程序后报内容出错:<br> &nbsp; Runtime error 216 at 004C36E6. &nbsp; &nbsp;<br><br>3.  ExitDLL 这个函数我发现系统在退出时好像没有执行。
 
详细源代码:<br>出错的源码下载地址:<br><br>http://www.cngrandpower.com/tanyong/jozosoft/down/help.rar
 
后退
顶部