请教用DELPHI该如何创建和调用DLL工程文件?

netboy 2000-02-04 12:00:00
我的操作步骤是这一样的:
1。 在DELPHI中新建了一个dll,保存为ff.DPR,代码如下
library ff;
uses
SysUtils,
Classes,
test in 'test.pas';{此窗体已建好}
{$R *.RES}
function cre():boolean;far;export;
var
ld:tform1;
begin
ld:=form1.Create(nil);
ld.show;
result:=true;
end;
exports cre;
begin
end.

2。编译生成ff.dll,保存在e:\temp\

3。另建一工程fd.dpr 来调用ff.dll 代码如下
unit test;
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
function cre():boolean;far;external'e:\temp\ff';
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if cre() then
showmessage('good');
end;
end.
4.编译fd.dpr出错信息为:
access violation at address 00461655 in module 'ff.dll'.read of
address ffffffff.
请众大侠赐教,最好附上源代码,谢谢!
...全文
328 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixq 2000-03-16
  • 打赏
  • 举报
回复
小弟是一个新手。很高兴看见这则消息!
playyuer 2000-03-15
  • 打赏
  • 举报
回复
应该是
欢迎访问 http://simideal.top263.net
VB、PB、Delphi 联合编程
playyuer 2000-03-15
  • 打赏
  • 举报
回复
欢迎访问 http://playyuer.to263.net
VB、PB、Delphi 联合编程

Delphi
Unit1 代码:

unit Unit1;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
MessageDlg('This is a Delphi MessageDlg !',mtInformation,[mbOK],0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
self.Caption:='This is a Delphi Modal Form !';
self.Button1.Caption:='This is a Delphi Button !';
end;

end.

==========================
VB call Delphi Dll code:
'一定要声明为 Long,虽然在 Delphi Dll 定义的是 Procedure (过程)
Private Declare Function ShowDelphiFormModal Lib "..\..\Project1.dll" () As Long
Private Sub Command1_Click()
ShowDelphiFormModal
End Sub
==================
PB call Delphi Dll Code:
//'一定要声明为 Long,虽然在 Delphi Dll 定义的是 Procedure (过程)
FUNCTION long ShowDelphiFormModal () LIBRARY "..\..\Project1.dll"
...
ShowDelphiFormModal()

holoboy 2000-03-14
  • 打赏
  • 举报
回复
看到一个例子,不知道有没有帮助?看一下吧。是转载的。
1.设计一个新项目,在其中包含的单元中声名一个供外部程序调用的过程或函数。
这些和您原来写普通程序都一样。
2.不一样的是:您需要在单元程序的接口部分声名的函数或过程的后面增加这样的关键字:EXPORT;
3.修改项目的代码,1.改 program为library,2.改forms为sharemem,
3在USES后增加EXPORTS关键字,关键字后是调用的过程和函数名,一般为:
USES。。。
EXPORTS
XXXXX;
{$R *.RES}
4.删除项目中BEGIN 、END之间的代码。
编译项目,就可以生成一个扩展名为DLL的动态连接库。

调用动态连接库的方法刚好同制作对应,大体分为下列几点:
1.在单元程序的接口部分声明外部过程,形式参数必须和设计的动态连接库相同。
Procedure xxxxxx(var xxxx:xxx ;………);far;external 'xxxxxxx';
2.在单元程序中,您可以象使用函数一样使用外部单元,编写子过程和函数。
3.项目文件中,增加SHAREMEM到USES单元,实现内存共享。
Lin 2000-03-13
  • 打赏
  • 举报
回复
在DLL中这样声明试试:
function cre(): Boolean; stdcall;

exports
cre;

implementation
...

在引用的时候不用声明了,只要在Uses中加上其单元即可。
Ray 2000-03-13
  • 打赏
  • 举报
回复
我有一个范例你要不要?
jll 2000-02-04
  • 打赏
  • 举报
回复
把两处function cre():boolean;far;export;中的far改为stdcall

5,386

社区成员

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

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