首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi7中新建的dll,dll中怎么声明函数,代码如下

2012-03-11 
delphi7中新建的dll,dll中如何声明函数,代码如下library Project2usesSysUtils,Classes{$R *.res}vari:

delphi7中新建的dll,dll中如何声明函数,代码如下
library Project2;


uses
  SysUtils,
  Classes;

{$R *.res}
var
  i: integer;

function myfuc1():integer;

function myfuc():integer;
begin

  Result := myfuc1();
end;

function myfuc1():integer;
begin
  Result := 0;
end;


begin


end.


编译错误提示信息

[Error] Project2.dpr(29): ';' expected but '.' found
[Error] Project2.dpr(31): Declaration expected but end of file found

[解决办法]
library Project2;


uses
SysUtils,
Classes;

{$R *.res}
var
i: integer;

function myfuc1():integer;stdcall;
begin
Result := 0;
end;


function myfuc():integer;stdcall;
begin

Result := myfuc1();
end;

exports
myfuc;

begin

end.


[解决办法]
函数得输出,用export
[解决办法]
因为你的函数实现也是全局的,不需要提前申明的。
library PTest;

{ 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;

{$R *.res}

function MyFunc: Integer; stdcall;
begin
Result := 20;
end;

exports
MyFunc;
begin

end.
[解决办法]
看书吧
[解决办法]
最近也在学习dll 还没入门
[解决办法]
调用单元 要引用 ShareMem
[解决办法]

Delphi(Pascal) code
library Project1;uses  SysUtils,  Classes;{$R *.res}var  i: integer;function myfuc():integer;stdcall;begin  Result := 0;end;function myfuc1():integer;stdcall;begin  Result := myfuc();end;exportsmyfuc, myfuc1;beginend. 

热点排行