Delphi 调用DLL中的窗体
2013-08-02 11:51
211 查看
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
begin
aForm := Tform(TheClass.Create).Create(nil);
try
aForm.ShowModal;
result:=true;
finally
FreeAndNil(aForm);
end;
end;
end;
exports
showform;
begin
end.
....
procedure RunDllForm(const DllFileName,DllFormName:String;const methodName:string);
type
TRunForm=function(formname:string):boolean;stdcall;
var
RunForm: TRunForm;
GetDllHWND: HWND;
begin
GetDllHWND := LoadLibrary(PChar(DllFileName));
try
if GetDllHWND < 32 then
begin
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('无效的方法名调用');
finally
FreeLibrary(GetDllHWND);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RunDllForm('project1.dll','form1','showform');
end;
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
begin
aForm := Tform(TheClass.Create).Create(nil);
try
aForm.ShowModal;
result:=true;
finally
FreeAndNil(aForm);
end;
end;
end;
exports
showform;
begin
end.
....
procedure RunDllForm(const DllFileName,DllFormName:String;const methodName:string);
type
TRunForm=function(formname:string):boolean;stdcall;
var
RunForm: TRunForm;
GetDllHWND: HWND;
begin
GetDllHWND := LoadLibrary(PChar(DllFileName));
try
if GetDllHWND < 32 then
begin
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('无效的方法名调用');
finally
FreeLibrary(GetDllHWND);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RunDllForm('project1.dll','form1','showform');
end;
相关文章推荐
- Delphi调用DLL文件里的窗体
- Delphi生成即调用带窗体的Dll
- Delphi 调用dll中的窗体
- delphi实现调用dll中的窗体 代码
- delphi 调用dll窗体
- Delphi程序调用C#.Net编译的DLL并打开窗体(详解)
- Delphi程序调用C#.Net编译的DLL并打开窗体(详解)
- 转自genispan的专栏 - delphi 调用dll窗体
- Delphi中动态调用DLL中的窗体
- [整理]c#简单调用DELPHI DLL封装窗体
- [轉]c#简单调用DELPHI DLL封装窗体
- Delphi程序调用C#.Net编译的DLL并打开窗体(详解)
- delphi 动态调用DLL
- java调用delphi写的DLL动态链接库
- Delphi 将窗体封装到DLL(中将EXE转换为DLL)-1
- C#调用delphi生成的dll获取CPU序列号(一)
- delphi如何调用C# dll
- C#调用delphi编写的dll时如何传入传出OLEVariant
- delphi调用VC++6的DLL
- Delphi中动态调用DLL的方法