关于DLL中的窗口重复调用问题~~~(50分)

  • 主题发起人 主题发起人 d村长
  • 开始时间 开始时间
D

d村长

Unregistered / Unconfirmed
GUEST, unregistred user!
我在一个动态链接库中创建了一个窗体,并用下面的方法在主程序中调用,第一次调用成功后,不关闭窗体,再重复调用一次,想让主程序从DLL中调出两个相同的窗口,程序就报错,下面给出原码,请高手帮忙解答一下.<br>DLL中的窗示窗口:<br>function show_form(AHandle: THandle; ACaption: String):BOOL;<br><br>begin<br><br><br><br>&nbsp;Application.Handle := AHandle;<br>&nbsp;Formt := TFormt.Create(Application);<br>&nbsp;try<br>&nbsp; &nbsp;Formt.Caption := ACaption;<br>&nbsp; &nbsp;Formt.Show ;<br>&nbsp; &nbsp;Result := False;<br>&nbsp;finally<br>&nbsp; &nbsp;Formt.Free;<br>&nbsp;end;<br>end;<br>主程序的调用:<br><br>procedure TForm1.IP1Click(Sender: TObject);<br>var &nbsp;//按钮的调用事件:调用过程<br>LibHandle: THandle;<br>show_form:tshow_form;<br>begin<br>&nbsp;Application.Title:='IP';<br>&nbsp;LibHandle := LoadLibrary('view.DLL');<br>&nbsp;try<br>&nbsp; &nbsp;if LibHandle = 0 then<br>&nbsp; &nbsp; &nbsp;raise EDLLLoadError.Create('无法成功装入指定模块,或系统发生未知错误!)');<br>&nbsp; &nbsp;@show_form := GetProcAddress(LibHandle, 'show_form');<br>&nbsp; &nbsp;if not (@show_form = nil) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;show_form(Application.Handle,Application.Title) ;<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp;RaiseLastWin32Error;<br>&nbsp;finally<br>&nbsp; &nbsp;FreeLibrary(LibHandle);<br>&nbsp;end;<br>end;<br>///////<br><br><br><br>我的目的就是同时能成功的调用DLL中的窗体很多次~~而不发生错误~
 
//前面不要声明Formt<br>function show_form(AHandle: THandle; ACaption: String):BOOL;<br>var<br>&nbsp; Formt:TFormt;<br>begin<br>&nbsp;Application.Handle := AHandle;<br>&nbsp;Formt := TFormt.Create(Application);<br>&nbsp;try<br>&nbsp; &nbsp;Formt.Caption := ACaption;<br>&nbsp; &nbsp;Formt.Show ;<br>&nbsp; &nbsp;Result := true;<br>&nbsp;except<br>&nbsp; &nbsp;Formt.Free;<br>&nbsp; &nbsp;result:=false;<br>&nbsp;end;<br>end;<br>
 
不要用show,用showmodal;<br>可以参考我在playicq 的exe 调用dll 的例子,还不完善。
 

Similar threads

后退
顶部