如何调用带form的dll,请给出简单例子!(300分)

  • 主题发起人 主题发起人 zjok
  • 开始时间 开始时间
Z

zjok

Unregistered / Unconfirmed
GUEST, unregistred user!
我看过以前的贴了。还是不太明
如何调用带form的dll,请给出简单例子!要有dll的源码 和 调用的语句,
没办法,做了很久都做不出
 
//DLL: FunLib.DLL

library FunLib;

uses
SysUtils,
Classes,
About in 'About.pas' {AboutForm};

{$R *.RES}

exports
AboutBox, //Show about box.

begin
end.



//About.pas

unit About;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, jpeg, ComCtrls;

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

var
AboutForm: TAboutForm;

procedure AboutBox (AHandle: THandle; Caption, FileName: Pchar); stdcall;

implementation

{$R *.DFM}

procedure AboutBox(AHandle : THandle; Caption, FileName: Pchar);
var
AboutForm : TAboutForm;
OldApplication : TApplication;
begin
{Assign the application's handle that call DLL to DLL's handle.}
OldApplication := TApplication.Create(Application);
OldApplication.Handle := Application.Handle;
Application.Handle := AHandle;
{Create and show logon form.}
AboutForm := TAboutForm.Create(Application);
try
AboutForm.Caption := Caption;
AboutForm.fcLabel1.Caption := Caption;
AboutForm.ShowModal;
finally
AboutForm.Free;
Application.Handle := OldApplication.Handle; //Recall application that call DLL.
end;
end;


end.



//CALL AboutBox
unit Unit1;

interface

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

type

TAboutForm = procedure(AHandle: THandle; Caption, FileName: Pchar); stdcall;

TForm1 = class(TForm)
Button6: TButton;
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Button6Click(Sender: TObject);
var
AHandle: THandle;
AboutBox: TAboutForm;
begin
AHandle := LoadLibrary('FunLib.dll');
try
if AHandle = 0 then
showmessage('无法装入FunLib.Dll。')
else begin
@AboutBox := GetProcAddress(AHandle, 'AboutBox');
AboutBox(Application.Handle, PChar('Test'), 'kk.txt');
end;
finally
FreeLibrary(AHandle);
end;
end;

end.
 
dll中函数
function plnwq(ahandle:Thandle):boolean;
var
frmlnwq:Tfrmlnwq;
begin
result:=false;
frmlnwq:=tfrmlnwq.create(nil);
application,handle:=ahandle;
try
frmlnwq.showmodal;
finally
frmlnwq.free;
end;
result:=true;
end;


声明
function plnwq(ahandle:Thandle):boolean stdcall;external 'agritax.dll'; //历年尾欠
调用
if plnwq(application.handle) then
begin
...
end;
 
建议你看Delphi Developer Guide第9章,有详细的说明和例子
包括调用DLL中的模态窗体与非模态窗体等等
 
多人接受答案了。
 
后退
顶部