该如何调用DLL,很简单,请知道

fjy351 2001-11-01 11:02:11
我写了一个DLL
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
procedure some;stdcall;
begin
form1.Show;
end;
{$R *.dfm}

end.
我要在另一个工程里调用它该如何调用:
unit Unit_dll;

interface

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

type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
procedure some;external 'project1.dll';
{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
some;
end;

end.
请问出什么错
...全文
143 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zengyufeng 2001-11-01
  • 打赏
  • 举报
回复
我给你写个简单的例子吧

library DLLTest;

interface

uses
Dialogs;

procedure Test;
begin
ShowMessage('Ok');
end;

exports
Test;

implementation
end.

然后新建一个工程引用这个DLL

procedure Test; external 'DLLTest.dll';

另:对于没有参数的过程不必要用stdcall。因为stdcall表示参数以堆栈形式(从右向左)传递,既然没有参数也就没必要用stdcall了
newyj 2001-11-01
  • 打赏
  • 举报
回复
http://www.csdn.net/Dev/Delphi/
cdkogh 2001-11-01
  • 打赏
  • 举报
回复
另外,在调用Dll时你需要如下单元:
unit MinMax;
interface
function Min(X, Y: Integer): Integer; stdcall;
function Max(X, Y: Integer): Integer; stdcall;
implementation
const DllName='MinMax.DLL';
function Min; external DllName;
function Min; external DllName;
end.
bubble 2001-11-01
  • 打赏
  • 举报
回复
@_@
cdkogh 2001-11-01
  • 打赏
  • 举报
回复
你的DLL肯定没法编译,我给你贴一些文档:

The structure of a DLL is identical to that of a program, except that a DLL begins with the reserved word library (instead of program).
The following example shows a DLL with two exported functions, Min and Max.

library MinMax;
function Min(X, Y: Integer): Integer; stdcall;

begin
if X < Y then Min := X else Min := Y;
end;

function Max(X, Y: Integer): Integer; stdcall;

begin
if X > Y then Max := X else Max := Y;
end;

exports

Min,
Max;

begin

end.

If you want your DLL to be available to applications written in other languages, it抯 safest to specify stdcall in the declarations of exported functions. Other languages may not support Object Pascal抯 default register calling convention.
DLLs can be built from multiple units. In this case, the library source file is frequently reduced to a uses clause, an exports clause, and the DLL抯 initialization code. For example,

library Editors;
uses EdInit, EdInOut, EdFormat, EdPrint;
exports

InitEditors,
DoneEditors index 17 name Done,
InsertText name Insert,
DeleteSelection name Delete,
FormatSelection,
PrintSelection name Print,
...
SetErrorHandler;

begin

InitLibrary;
end.

You can put exports clauses in the interface or implementation section of a unit. Any library that includes such a unit in its uses clause automatically exports the routines listed the unit抯 exports clauses梬ithout the need for an exports clause of its own.
Only routines that a library explicitly exports are available for importing by other libraries or programs.

以上内容可在Delphi IDE下键入library,然后按F1得到.
fjy351 2001-11-01
  • 打赏
  • 举报
回复
但是我那么调用,老实出错啊
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
procedure some;stdcall;
begin
showmessage('sdf');
{$R *.dfm}

end.
我要在另一个工程里调用它该如何调用:
unit Unit_dll;

interface

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

type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
procedure some;external 'project1.dll';
{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
some;
end;

end.
请问出什么错




hellion 2001-11-01
  • 打赏
  • 举报
回复
只是想实现创建DLL,调用DLL的话把 form1.Show;改为ShowMessage('esdfdfd')一样能达到目的
fjy351 2001-11-01
  • 打赏
  • 举报
回复
上面已经贴出来了啊,我现在没有写代码,只是想实现创建DLL,调用DLL,
因为初学,不是太会
zengyufeng 2001-11-01
  • 打赏
  • 举报
回复
贴出你的代码
fjy351 2001-11-01
  • 打赏
  • 举报
回复
可是我创建的时候出错,不知道怎么回事
zengyufeng 2001-11-01
  • 打赏
  • 举报
回复
晕倒,你的dll里的form1都没创建,你show什么啊?当然出错!

dll里的form是不会自动创建的!
fjy351 2001-11-01
  • 打赏
  • 举报
回复
该如何写啊,请指教
newyj 2001-11-01
  • 打赏
  • 举报
回复
dll就写的不对

5,386

社区成员

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

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