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


则程序没有任何错误!

请各位高手多多指教!
...全文
138 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Un1 2000-07-24
  • 打赏
  • 举报
回复
http://expert.csdn.net/Topic/16363.shtm
Michaelyfj 2000-07-23
  • 打赏
  • 举报
回复
关注...

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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