DLL相互调用的说明(300分)

  • 主题发起人 主题发起人 bizzar
  • 开始时间 开始时间
B

bizzar

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用一个DLL调用另一个DLL,请问如何说明?最好能有简单的例子,很急!!


先谢了!
 
给你一个例子。
用到三个Project,都很简单。
**********************
DLL1.dpr
**********************
library DLL1;

uses
SysUtils,
Classes,
DLL1Main in 'DLL1Main.pas' {frmDLL1};

exports
DLL1Entry;

{$R *.RES}

begin
end.
********************
DLL1Main.pas
********************
unit DLL1Main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TfrmDLL1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmDLL1: TfrmDLL1;

procedure DLL1Entry;

implementation

{$R *.DFM}

procedure DLL1Entry;
begin
frmDLL1 := TfrmDLL1.Create(nil);
try
frmDLL1.ShowModal;
finally
frmDLL1.Free;
end;
end;

end.
**********************
DLL2.dpr
**********************
library DLL2;

uses
SysUtils,
Classes,
DLL2Main in 'DLL2Main.pas';

exports
DLL2Entry;

{$R *.RES}

begin
end.
************************
DLL2Main.pas
************************
unit DLL2Main;

interface

uses
Windows, SysUtils;

procedure DLL2Entry;

implementation

procedure DLL2Entry;
var
TH: THandle;
DP: TProcedure;
begin
TH := LoadLibrary('DLL1');
DP := GetProcAddress(TH,'DLL1Entry');
if @DP <> nil then
DP;
FreeLibrary(TH);
end;

end.
******************************
Project1.dpr
******************************
program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
**********************
Unit1.pas
**********************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

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
TH: THandle;
DP: TProcedure;
begin
TH := LoadLibrary('DLL2');
DP := GetProcAddress(TH,'DLL2Entry');
if @DP <> nil then
DP;
FreeLibrary(TH);
end;

end.
自己试一下吧。
 
后退
顶部