dll中函数有多个返回值

datree 2008-11-29 10:46:48
我想在dll里定义一个函数,而这个函数有多个返回值 函数的定义该怎么写?
这样写大家看看为什么不能用:
var
a :array[1..10] of real;
function allowance(B: array[1..10] of Real):a;
begin
end;
我是个新手,愿大家指教的时候,尽量解释得详细些,有例子最好。谢谢大家了!
...全文
110 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
datree 2008-11-30
  • 打赏
  • 举报
回复
楼上大哥能不能给个完整的列子,我好参考一下。
另我要返回值的个数比较的多,你说的两种方法请再说详细点。
datree 2008-11-30
  • 打赏
  • 举报
回复
知道怎么用了
谢谢了
僵哥 2008-11-30
  • 打赏
  • 举报
回复
GetMem之后,记得FreeMem,测试程序,我就没写了。
僵哥 2008-11-30
  • 打赏
  • 举报
回复
DLL源代码
library GenRandoms;

{$R *.res}

function GetRandoms( const Out_Random_Arr: PIntegerArray (*目标地址,请在主调用程序分配足够的内存*)
; const In_Random_Count: Word (*随机数个数*)
): Boolean; stdcall;
var
I: Integer;
begin
for I := 0 to In_Random_Count - 1 do
begin
Out_Random_Arr[I] := Random(10000);
end;
Result := true;
end;

exports
GetRandoms;
begin
end.

测试程序
unit uTestMain;

interface

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

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

var
Form2: TForm2;
function GetRandoms( const Out_Random_Arr: PIntegerArray (*目标地址,请在主调用程序分配足够的内存*)
; const In_Random_Count: Word (*随机数个数*)
): Boolean; stdcall;external 'GenRandoms.dll';
implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
Rnds: PIntegerArray;
iCount: Integer;
I: Integer;
begin
iCount := 10;
GetMem(Rnds,iCount * sizeof(Integer));
fillchar( PAnsiChar(Rnds)^,iCount * sizeof(Integer),0);
GetRandoms(Rnds,iCount);
for I := 0 to iCount - 1 do
ShowMessage(IntToStr(Rnds[i]));
end;

end.
僵哥 2008-11-29
  • 打赏
  • 举报
回复
如果是有限个,则定义多个参数,否则就定义一个指针加一个用于指示指针所指向的参具体的个数。或者使用结构体等。
function GetArray(Command: Integer(*指令*); var Param0(*第一个返回参数*), Param1(*第二个返回参数*), Param2(*第三个返回参数*): Real): Boolean; stdcall;
僵哥 2008-11-29
  • 打赏
  • 举报
回复
通过参数返回。
datree 2008-11-29
  • 打赏
  • 举报
回复
我将定义改成:
function aa(b:array of Real ):array[1..3] of Real ;
不能编译,报错:Identifier expected but ‘array’ found 和 Array type required

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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