这是一个vb调用dll(vc6做)的高难度问题

webptg 2000-03-05 10:40:00
我在vc的dll中定义了一个函数:
int far pascal __stdcall rec(int v1,int v2,int v3,short int *data)
{
....
}

我在vb里调用这个函数时声明如下:
declare rec function ...(...,ByRef data as integer)
....
dim shuju(0 to 10) as integer
call rec(a,b,c,shuju(0))
其中a,b,c是我要发送的数据,shuju(0 to 10)是我要接收的整数。
现在问题是:
有时调用此函数时没有出现问题,但有时出现如下提示:
debug error!
program d:\vb98\vb6.exe
module
file:i386\chkesp.c
line:42
The value of ESP was not properly saved across a funtion call,This
is usually a result of calling a funtion declared with one calling
conventin with a funtion pointer declared with a different calling
convention.
调用此函数出错后,以后再调用时均不正确.
这个提示好象是dll调用约定错误。
恳请各位大虾帮我看看错在哪里,不胜感激!
                         
...全文
240 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
webptg 2000-03-08
  • 打赏
  • 举报
回复
恳请各位大虾帮我看看错在哪里!!
webptg 2000-03-07
  • 打赏
  • 举报
回复

我照Unl提供的方法声明dll(Public Declare .....(...,ByRef data as Any),已没出现Debug Error的错误了,在此表示衷心的感谢!
另外,还有一个错误:
我在dll中嵌入了asm如:
int __stdcall rec(int v1,int v2,int v3,short int *data)
...
_asm{
...
mov a1,1
mov a2,10
mov a3,100
mov a4,1000
}
data[0]=a1;
data[1]=a2;
data[2]=a3;
data[3]=a4;
return 1;
}
假设a1,a2,a3,a4是我要得到的数据(其值是随时改变的),当我反复调用此函数时,
有时得到的数据不正确。
我通过vb调用:
dim shuju(0 to 10) as integer
call rec(a,b,c,shuju(0))
出错时shuju(0)=-13108 ,没有得到我所要的数据。当我再次启动程序调用dll的rec
时都出错,但当我运行与嵌入的那段asm功能相同的asm生成的exe(dos下)后,再调用dll中rec,则恢复正常,反复调用又可能出现错误。不知是何原因!



webptg 2000-03-07
  • 打赏
  • 举报
回复
river99,你好!
请您给我一个具体的解决方案好吗?最好就这个问题烦您给我一个示例,谢谢!
river99 2000-03-07
  • 打赏
  • 举报
回复
多次调用错的问题,我以前也碰到过,但没有找到原因(不好意思)。最后是利用ATL解决这个问题,把整个动态库改变成一个ACTIVEX控件,象a1,a2,a3,shuchu什么的全部改造成属性。这样就不会再出现连续多次调用导致数据不对的现象。
river99 2000-03-05
  • 打赏
  • 举报
回复
问题出在VB中的定义,VC的INT型数据为4个字节,而VB中的integer类型为两个字节,如果返回值超过65535,调用就会出错。
river99 2000-03-05
  • 打赏
  • 举报
回复
VC中的声明:
int WINAPI rec( int v1, int v2, int v3, int * data)
VB中的声明:
declare function rec ...( ..., byref data as long ) as long
使用时:
dim a as long, b as long, c as long
dim shuju(0 to 10) as long
...
call rec(a, b, c,shuju(0) )
注意:传送的是地址,要保证dll中对data的操作不能越界。
webptg 2000-03-05
  • 打赏
  • 举报
回复
恳请各位大虾帮我看看错在哪里!
webptg 2000-03-05
  • 打赏
  • 举报
回复
我把__stdcall前的far pascal调用协议去掉后还是有同样的问题.
Un1 2000-03-05
  • 打赏
  • 举报
回复
把C中的申明改为:

int __stdcall rec(int v1,int v2,int v3,short int *data)

7,762

社区成员

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

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