DLL中如何使用窗体?
我用Delphi 3.0 编写一显示输入用户名和口令的对话框的DLL后,在调用时出现访问错误.原代码如下:
//DLL实现单元
unit dll;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
Tinputbox = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
end;
var
inputbox: Tinputbox;
function iinput:String;export;
implementation
{$R *.DFM}
function iinput:String;
var
str:String;
begin
inputbox:=TInputBox.Create(application);
if InputBox.ShowModal=1 Then str:=inputBox.edit1.Text
else
str:='';
inputbox.Free;
iinput:=str;
End;
end.
//DLL工程单元
library dlldemo;
uses
ShareMem,
dll in 'dll.pas' {inputbox};
{$R *.RES}
Exports
iinput;
begin
end.
//DLL调用单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
hand:THandle;
func:function:String;
begin
hand:=LoadLibrary('d:\dlldemo.dll');
func:=GetProcAddress(hand,'iinput');
form1.Edit1.Text:=func;
FreeLibrary(hand);
end;
end.