如何动态加载DLL文件,实现如下功能
DLL文件:  test.dll 内容是显示一个登陆窗体,输入
正确的信息后,显示登陆成功
菜单:
  加载DLL文件
  显示DLL内容
  释放DLL文件
================================

解决方案 »

  1.   

    最好也详细讲解一下关于引用DLL文件的两种方式
    动态加载
    静态加载
      

  2.   

    procedure TForm1.SpeedButton2Click(Sender: TObject);
    type
        TproPoint=procedure (hand:thandle);stdcall;
    var callFun:TproPoint;
        handle:Thandle;
    begin
      Handle := LoadLibrary('test.dll');
      if Handle<>0 then
      begin
        @callFun:=GetProcAddress(Handle,'dll输出函数');
        if @callFun<>nil then
        begin
          callFun(Application.handle);
        end;
        FreeLibrary(Handle);
      end;
    end;
      

  3.   

    显示DLL内容我不知道;
    其他的问题我可以搞定;楼上的就是动态加载和释放;
    静态加载就是如下;
    procedure OutputDebugString; external kernel32 name 'OutputDebugStringA';
    引用Dll的函数说明;
      

  4.   

    dddddddddddddddd
     不明白呀
      

  5.   

    -------------dll----------------------
    library login;uses
      SysUtils,
      Classes,
      Forms,
      Unit_Login in 'Unit_Login.pas' {Form_Userlogin};{$R *.res}Exports
      Userlogin name 'Userlogin';  //这里调用Unit_Login的函数
    beginend.----------------Unit_Login-------------------
    unit Unit_Login;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm_Userlogin = class(TForm)
        Edit2: TEdit;
        BitBtn1: TBitBtn;
        BitBtn2: TBitBtn;
        Edit1: TEdit;
        Label1: TLabel;
        Label2: TLabel;
        procedure BitBtn2Click(Sender: TObject);
        procedure BitBtn1Click(Sender: TObject);
      private
        V_Pass: Boolean;
        function Userpass(auid, apwd: String): Boolean;
      public
      end;var
      Form_Userlogin: TForm_Userlogin;
      Function Userlogin(aHandle: Integer): Boolean; Stdcall; //申明是要输出的
    implementation{$R *.dfm}Function Userlogin(aHandle: Integer): Boolean;
    Begin
      Application.Handle := aHandle; //这里接收调用端的句柄,目的是不在任务栏出现2个任务
      Application.CreateForm(TForm_Userlogin, Form_Userlogin);
      With Form_Userlogin Do
      Begin
        V_Pass := False;
        try
          ShowModal;
        finally
          Result := V_Pass;
          FreeAndNil(Form_Userlogin);
        end;
      End;
    End;//判断用户名称,密码
    Function TForm_Userlogin.Userpass(auid, apwd: String):Boolean;
    Begin
      Result := Sametext(auid, 'admin') And SameText(apwd, 'admin');
    End;
    procedure TForm_Userlogin.BitBtn1Click(Sender: TObject);
    begin
      If Not Userpass(Edit1.Text, Edit2.Text) Then
      Begin
        Application.MessageBox(Pchar('用户名称或密码错误!'), '系统提示', 64);
        Exit;
      End;
      V_Pass := True;
      Close;
    end;procedure TForm_Userlogin.BitBtn2Click(Sender: TObject);
    begin
      V_Pass := False;
      Close;
    end;end.
    ----------------调用方法--------
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        BitBtn2: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
        procedure BitBtn2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}//静态调用
    function Userlogin(aHandle: Integer): Boolean; stdcall;
      external '..\login.dll' Name 'Userlogin';  //注意dll文件所在目录
    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      If Userlogin(Handle) Then
      Application.MessageBox(Pchar('登录成功!'), '系统提示', 64) Else
      Application.MessageBox(Pchar('登录失败!'), '系统提示', 64);
    end;
    //动态调用,格式一般很固定的。
    procedure TForm1.BitBtn2Click(Sender: TObject);
    type
      TIntFunc = function(aHandle: Integer): Boolean; stdcall;
    var
      Th:Thandle;
      Tf:TIntFunc;
      Tp:TFarProc;
    begin 
      Th := LoadLibrary('..\login.dll'); {装载DLL} //注意dll文件所在目录
      if Th > 0 then
      try
        Tp := GetProcAddress(Th, PChar('Userlogin'));
        if Tp<>nil then
        begin
          Tf := TIntFunc(Tp);
          If Tf(Handle) Then  {调用TestC函数}
          Application.MessageBox(Pchar('登录成功!'), '系统提示', 64)Else
          Application.MessageBox(Pchar('登录失败!'), '系统提示', 64);
        end else
        ShowMessage('Userlogin函数没有找到');
      finally
        FreeLibrary(Th); {释放DLL}
      end else
      ShowMessage('login.dll没有找到');
    end;end.
      

  6.   

    谢谢各位,动态连接库DLL,我看明白了点
      

  7.   

    哈哈.........................
    分是小的点,但是情意在吗>>>>>>>>>>>>>>>>>>