首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

*vb传递数组到dll的有关问题*

2012-01-05 
*******************vb传递数组到dll的问题***************************vc中函数定义如下:int__stdcallWim

*******************vb传递数组到dll的问题***************************
vc中函数定义如下:
int   __stdcall   WimDev_Data(int   VelID,long   *Weight,long   *WtLimit,int   AxisType[10],long   AxisWeight[10],double   *speed)

我在vb中声明如下:
Declare   Function   WimDev_Data   Lib   "WtSys_Dll.dll "   (ByVal   carno   As   Long,   ByRef   weight   As   Long,   ByRef   wtlimit   As   Long,   ByRef   Axistype()   As   Long,   ByRef   Axisweight()   As   Long,   ByRef   speed   As   Long)   As   Long

在程序中调用方式为
Dim   ret
Dim   weight   As   Long
Dim   wtlimit   As   Long
Dim   Axistype(1   To   10)   As   Long
Dim   Axisweight(1   To   10)   As   Long
Dim   speed   As   Long
ret   =   WimDev_Data(1,   weight,   wtlimit,   Axistype,   Axisweight,   speed)

weight,weight能够返回正确,可Axistype和Axisweight和speed返回都不对

改为
ret   =   WimDev_Data(1,   weight,   wtlimit,   Axistype(1),   Axisweight(1),   speed)
提示   类型不匹配,缺少数组

请哪位高手看看到底该怎么调用?(dll没问题,在vc下返回正常),多谢


[解决办法]
ret = WimDev_Data(1, weight, wtlimit, Axistype(0), Axisweight(0), speed)
试下呢。

[解决办法]
楼主测试一下下面两个方案看看:

方案一
Declare Function WimDev_Data Lib "WtSys_Dll.dll " (ByVal carno As Long, ByRef weight As Long, ByRef wtlimit As Long, ByRef Axistype() As Long, ByRef Axisweight() As Long, ByRef speed As Double) As Long

Dim ret As Long
Dim weight As Long
Dim wtlimit As Long
Dim Axistype(0 To 9) As Long
Dim Axisweight(0 To 9) As Long
Dim speed As Double
ret = WimDev_Data(1, weight, wtlimit, Axistype, Axisweight, speed)


方案二
Declare Function WimDev_DataLib "WtSys_Dll.dll " (ByVal carno As Long, ByRef weight As Long, ByRef wtlimit As Long, ByVal Axistype As Long, ByVal Axisweight As Long, ByRef speed As Double) As Long

Dim ret As Long
Dim weight As Long
Dim wtlimit As Long
Dim Axistype(0 To 9) As Long
Dim Axisweight(0 To 9) As Long
Dim speed As Double
ret = WimDev_Data(1, weight, wtlimit, VarPtr(Axistype(0)), VarPtr(Axisweight(0)), speed)

[解决办法]
int __stdcall WimDev_Data(int VelID,long *Weight,long *WtLimit,int AxisType[10],long AxisWeight[10],double *speed)

我在vb中声明如下:
Declare Function WimDev_Data Lib "WtSys_Dll.dll " (ByVal carno As Long, ByRef weight As Long, ByRef wtlimit As Long, ByRef Axistype() As Long, ByRef Axisweight() As Long, ByRef speed As Long) As Long

申明和你定义的对不上吧

热点排行