我搜索了N篇文章,好象谈到调用DLL里的窗体时都是说
的静态调用,为什么就没有说动态调用的?难道大家都
和我一样不懂???
谁能给我一段最简单的动态调用DLL里一个空form的代码? DLL:-------------------------library test;uses
SysUtils,
Classes,
forms,
Unit in 'unit.pas' {form1};{$R *.res}
procedure Show_form1;stdcall;
var form:Tform1;
begin
form:=Tform1.Create(Application);
with form do
begin
showModal;
free;
end;
end;exports
Show_form1;
begin
end.
//调用程序---------------------------------------------------unit main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls,comm;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;//这里是否要做什么声明????????????var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var h:thandle;
begin
h:=loadlibrary('testdll.dll'));
try
????????????????????????????????????????????
//这里怎么写?????
finally
h.free;
end;
end;end.
的静态调用,为什么就没有说动态调用的?难道大家都
和我一样不懂???
谁能给我一段最简单的动态调用DLL里一个空form的代码? DLL:-------------------------library test;uses
SysUtils,
Classes,
forms,
Unit in 'unit.pas' {form1};{$R *.res}
procedure Show_form1;stdcall;
var form:Tform1;
begin
form:=Tform1.Create(Application);
with form do
begin
showModal;
free;
end;
end;exports
Show_form1;
begin
end.
//调用程序---------------------------------------------------unit main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls,comm;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;//这里是否要做什么声明????????????var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var h:thandle;
begin
h:=loadlibrary('testdll.dll'));
try
????????????????????????????????????????????
//这里怎么写?????
finally
h.free;
end;
end;end.
解决方案 »
- Field XXX cannot be modified
- 如何将string类型转换成char类型??????
- 一个关于接口(双机通信)的小问题,大家进来看看。
- dbgrideh问题!关于下拉列表。哥哥们帮忙看看!
- 如何用代码实现radiogroup的某个item被选中?
- 我在adotable中删除数据它老是报错:”键列信息在最后读取中改变“(急用)
- csdn真的要完蛋了,怎么回复不了?还有看不到本人回答的东东。
- 遇到Delphi一个奇怪的问题
- server2000数据库的备份与恢复的代码操作
- 自定义问题
- Excel.Application不能打开Excel?
- 求助:如何提高程序的处理速度(筛选两个文本中不同的内容)
下面是个例子:
procedure Tfomxxx.LoadDLL(const DLLName, MethodName: String);
var
OneHandle : THandle; //定义一个句柄变量
FAM_DLLFOM : TFamDll;
begin
OneHandle := LoadLibrary(PAnsiChar(DLLName)); //动态载入DLL,并返回其句柄
try
if OneHandle > 0 then
@FAM_DLLFOM:= GetProcAddress(OneHandle, PAnsiChar(MethodName));
If OneHandle<=0 then
MessageBox(Self.Handle, '加载模块出错,请尝试重新更新程序。', '操作提示', MB_OK + MB_ICONINFORMATION)
else
begin
FAM_DLLFOM(Application.Handle);
Self.Repaint;
end;
finally
Freelibrary(OneHandle); // 卸载DLL
end;
end;
我也碰到了一个问题,拿出来大家共同讨论,我在动态调用dl文件的时候老出现
access violation at address 0103ff32 in module 'vcl70.bpl',read of address 00000000
的错误,在dll中设置断点也无法设置(已经设置了宿主程序),希望大家给予指教。
libhandle:THandle;
ShowFormCreate:procedure;stdcall;
procedure TForm1.Button2Click(Sender: TObject);
begin
libhandle:=LoadLibrary(PChar('D.dll'));
@ShowFormCreate:=GetProcAddress(libhandle,'ShowFormCreate');
ShowFormCreate;
end;
//Dll端 D.dll
uint1
Procedure ShowFormCreate;stdcall;
procedure ShowFormCreate;
begin
Form1:=TForm1.Create(nil);
Form1.Show;
end;
我刚试过,没问题。至于动态调用dll的文章csdn和dfw中都有.