关于调用DLL函数返回多个参数的问题!(50)

S

spyder

Unregistered / Unconfirmed
GUEST, unregistred user!
谁帮忙给看看下面的代码!为啥错误啊?我是想在调用DLL函数中的返回的数组,将数组中的数值添加到listbox1中!谁帮忙看看啊!主程序代码unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type arr=array of integer;
TForm1 = class(TForm) Panel1: TPanel;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementationtype tnumfunction=function:integer;stdcall;
ttfunction=function:arr;stdcall;
tlfunction=function:arr;stdcall;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var num1,num2:array of integer;
dllname:string;
m,i:integer;
l:array of integer;
t:array of integer;
tfunction:ttfunction;
lfunction:tlfunction;
numfunction:tnumfunction;
hinst:thandle;
fpointer1,fpointer2,fpointer3:tfarproc;
begin
getdir(0,dllname);
dllname:=dllname+'/mydll.dll';
hinst:=safeloadlibrary(dllname);
if hinst>0 then
try fpointer1:=getprocaddress(hinst,'num');
fpointer2:=getprocaddress(hinst,'lp');
fpointer3:=getprocaddress(hinst,'tp');
if (fpointer1<>nil) and (fpointer2<>nil) and (fpointer3<>nil)then
begin
numfunction:=tnumfunction(fpointer1);
lfunction:=tlfunction(fpointer2);
tfunction:=ttfunction(fpointer3);
m:=numfunction;
setlength(num1,m);
setlength(num2,m);
for i:=0 to m do
begin
num1:=tfunction;
num2:=lfunction;
listbox1.Items.Add(inttostr(num1)+''+inttostr(num2));
end;
end else
showmessage('111');
finally freelibrary(hinst);
end else
showmessage('222');
end;
end.
DLL函数代码library Project1;{ 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;type arr=array of integer;{$R *.res}function num:integer;stdcall;
begin
result:=2;
end;
function lp:arr;stdcall;
begin
setlength(result,3);
result[0]:=20;
result[1]:=40;
result[2]:=60;
end;
function tp:arr;stdcall;
begin
setlength(result,3);
result[0]:=20;
result[1]:=40;
result[2]:=60;
end;
exports num,lp,tp;
begin
end.
 

白河愁

Unregistered / Unconfirmed
GUEST, unregistred user!
打rtl补丁。
 
L

liuminghao

Unregistered / Unconfirmed
GUEST, unregistred user!
我没碰到如此问题,我用D7
 
Z

znxia

Unregistered / Unconfirmed
GUEST, unregistred user!
setlength(num1,m);
setlength(num2,m);
for i:=0 to m do
--> for i:=0 to m-1 do
最好用 for I:=low(num1) to High(num1)
 

不能没有你

Unregistered / Unconfirmed
GUEST, unregistred user!
对于dll,建议传入参数指针,然后在dll中赋值。
 

Similar threads

I
回复
0
查看
669
import
I
I
回复
0
查看
566
import
I
I
回复
0
查看
679
import
I
顶部