下面图老师小编跟大家分享调用DLL文件中的FORM,一起来学习下过程究竟如何进行吧!喜欢就赶紧收藏起来哦~
【 tulaoshi.com - 编程语言 】
作者:e梦缘
好久发表文章了!!!
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
调用DLL文件中的FORM,具体实现过程如下:
library Project1;uses SysUtils, Classes,Forms,windows,dialogs, Unit1 in 'Unit1.pas' {Form1};{$R *.res}function showform(formname:string):boolean;stdcall;var TheClass: TPersistentClass; aForm: TForm;begin result:=false; {如果您的Dll中有很多FORM,请在这儿注册哦 RegisterClasses([TForm1,TForm2,TForm3,...]); } RegisterClasses([TForm1]); TheClass := GetClass('T' + FormName); if (TheClass = nil) then exit; if TheClass.InheritsFrom(TForm) then beginaForm := Tform(TheClass.Create).Create(nil);try aForm.ShowModal; result:=true;finally FreeAndNil(aForm);end; end;end;exportsshowform;beginend.
....procedure RunDllForm(const DllFileName,DllFormName:String;const methodName:string);typeTRunForm=function(formname:string):boolean;stdcall;var RunForm: TRunForm; GetDllHWND: HWND;begin GetDllHWND := LoadLibrary(PChar(DllFileName)); tryif GetDllHWND 32 thenbegin MessageBox(0, Pchar('没有找到'+DllFileName+'DLL文件!'),'加载DLL失败', MB_OK); Exit;end;@RunForm := GetProcAddress(GetDllHWND,pchar(methodName));if @RunForm nil then try RunForm(DllFormName); except raise Exception.Create('对不起,找不到T' + DllFormName+ '窗体!'); end else raise Exception.Create('无效的方法名调用'); finallyFreeLibrary(GetDllHWND); end;end;procedure TForm1.Button1Click(Sender: TObject);beginRunDllForm('project1.dll','form1','showform');end;....
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
来源:http://www.tulaoshi.com/n/20160219/1601877.html
看过《调用DLL文件中的FORM》的人还看了以下文章 更多>>