C做的dll被 VB 程序调用
lsd 2000-07-22 08:47:00 如下程序:
int test(char s[121], double x[7])
{
sprintf(s,"hello, the world!");
for(register i=0;i<7;i++)
x[i]=0.1*i;
return 0;
}
需要作成动态炼接库为 VB 程序调用。
我作了好多次,都不成功。实际上,对于如下程序
int _stdcall test(double x[2])
{
*x=1.1;
*(x+1)=2.2;
return 0;
}
作成 dll 被 VB调用, 该函数执行完后,对数组作操作,
总说下标越界。
在 VB中这样调用:(假设dll 为 test.dll)
private declare function test lib"test" (ByRef x() As double) As integer
sub try
dim r as integer
dim x(2) as double
x(0)=5.5
x(1)=5.5
debug.print x(0), x(1)
r=test(x())
debug.print x(0),x(1)
end sub
在执行第二个debug.print语句时出现所说的错误。
若test定义换成;
int _stdcall test(double *x,double *y)
{
*x=1.1;
*y=2.2;
return 0;
}
vb中如下用:
private declare function test lib"test" (ByRef x As double, ByRef y As double ) As integer
sub try
dim r as integer
dim x(2) as double
x(0)=5.5
x(1)=5.5
debug.print x(0), x(1)
r=test(x(0),x(1))
debug.print x(0),x(1)
end sub
则程序没有任何错误!
请各位高手多多指教!