试着编写了一个带窗体的DLL,可调用的时候总是说无法初始化?疑惑,郁闷

helpforever 2003-12-15 02:16:03
DLL代码:
.DPR
library CheckPasswordForm;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
XcqCheck in 'XcqCheck.pas' {XcqForm};

{$R *.res}

begin
end.

DLL中的窗体
XcqCheck.pas
unit XcqCheck;

interface

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

type
TXcqForm = class(TForm)
XcqEdit: TMaskEdit;//密码输入框
OkBtn: TButton;
procedure OkBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
XcqForm: TXcqForm;
Check: Boolean;//验证输入密码的正确性
function CheckPassword: Boolean;export;
//本dll文件的关键实现


implementation

{$R *.dfm}

procedure TXcqForm.OkBtnClick(Sender: TObject);
begin
if XcqEdit.Text = 'xcq' then
Check := True;
Close;

end;

function CheckPassword;export;
begin
Check := False;
XcqForm := TXcqForm.Create(Application);
//创建密码输入框
XcqForm.ShowModal;//显示密码输入框;
//注意:不能用XcqForm.Show!
Result := Check;//返回给调用本dll的应用程序判断
XcqForm.Free;//释放本dll文件所占资源
end;

end.




/////
测试调用的代码
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
function CheckPassword: Boolean; external 'CheckPasswordForm.dll' name 'CheckPassword';

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckPassword then
begin
Showmessage('DLL is Ok');//如XcqQuery.Open;
end;

end;
...全文
20 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzybird 2003-12-15
  • 打赏
  • 举报
回复
Dll的library CheckPasswordForm;中没定义Exports 引出函数。
helpforever 2003-12-15
  • 打赏
  • 举报
回复
大虾能不能说说?我是看着例程写的
yurenjf 2003-12-15
  • 打赏
  • 举报
回复
原则错误

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧