200分求助:关于用C语言调用delphi编写的DLL问题(200分)

  • 主题发起人 moweiming
  • 开始时间
M

moweiming

Unregistered / Unconfirmed
GUEST, unregistred user!
本人最近用delphi开发DLL,用delphi测试均无问题,但在提交给同事,用C调用时出现问题。
一般的dll函数(没有参数传递,或简单参数值传递的都没有问题,但是如果传递数组时就老是错误)

dll函数的原型: function myfunc(tbuff:array of single
tlen:integer):integer;
函数功能是处理一个浮点数类型的数组,tlen指明了数组的个数,结果。

在delphi程序中调用方法:
var
abuff:array[0..99] of single;
alen:integer;

....
result:=myfunc(abuff,10);
result:=myfunc(abuff,20);
调用结果没问题。
但是在C中这个数组该如何传递?
float abuf[100];
....
result=myfunc(&abuf[0],10);
result=myfunc(abuf,10);
这样调用均导致系统出错。
怀疑还是参数指针传递的问题!那位高手能帮个忙啊,不胜感激!
 
function myfunc(tbuff: Pointer
tlen:integer):integer
stdcall;
 
你用Delphi写的dll里面,函数声明必须用stdcall来表明调用规则:
function myfunc(tbuff:array of single
tlen:integer):integer;stdcall;
 
然后重新编译dll
 
To zqw0117:
sorry,忘了说明,这个stdcall我肯定是有的
function myfunc(tbuff:array of single
tlen:integer):integer;stdcall

To kkyy:
一定要写成 tbuff: Pointer 吗?
 
C中的.h里是这样定义的原型可以吗:
int myfunc(float *tbuff, int tlen);
 
array of single不是C标准参数类型,可能会有些问题,还是直接传指针好点,你试试应该就知道了
 
多谢kkyy的指点,现在已经搞定 , pascal的数组传递的确有个性啊,仔细Debug发现它不仅传递了数组指针,还传递了数组维数啊。
因此,c中的原型定义改为 long myfunc(float tbuff[], long buffdim, long tlen); 就OK啦。
 

Similar threads

S
回复
0
查看
962
SUNSTONE的Delphi笔记
S
S
回复
0
查看
784
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部