我搜索了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.

解决方案 »

  1.   

    你在调用了loadlibrary之后需要调用GetProcAddress。
    下面是个例子:
    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中设置断点也无法设置(已经设置了宿主程序),希望大家给予指教。
      

  2.   

    //调用端
    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中都有.
      

  3.   

    在调用窗体中向DLL传送Application,Screen这两个参数即可