VB调用第三方(疑VC++)封装dll时,涉及到char*类型的入参格式时报“DLL调用约定异常”
VB调用第三方(疑VC++)封装dll时,涉及到char*类型的入参格式时报“DLL调用约定错误”
2.2写磁卡
int CT_WriteCard( int nPort,
char* BpNo,
int nTimeOut,
int nMode,
int nDelimiter,
char *szTr2Data,
char *szTr3Data )
2.2.1参数
参数 说明
nPort 0-hid设备,>0串口号
BpNo 转口,NULL-无转口,其他为对应转口
nTimeOut 超时时间,单位秒
nMode 2-读2磁道,3-读3磁道,23-读23磁道
nDelimiter 字符集格式,0-ISO格式,1-IBM格式
szTr2Data 二磁道数据
szTr3Data 三磁道数据
各位大大,以上是某公司读卡器dll封装的函数调用说明,我要在vb里调用,贴下我的代码大家帮忙看下哪有问题(小菜):
调试时报DLL调用约定错误,大家能帮忙看一下吗,非常感谢
------解决方案--------------------
你贴出的函数原型是 CT_WriteCard( ) 的,使用的代码却是 CT_ReadCard( ) 的。
这个没太大的“参考价值”呀。
另外一个比较重要的问题,在 C++ 中的 int类型,在 VB6中要用Long才能跟它匹配!
------解决方案--------------------
Public Declare Function CT_ReadCard Lib "CENT_MsgReader.dll" (ByVal nPort As Long, ByRef BpNo As Byte, ByVal nTimeOut As Long, ByVal nMode As Long, ByVal nDelimiter As Long, ByVal nTr2DataLen As Long, ByRef szTr2Data As Byte, ByVal nTr3DataLen As Long, ByRef szTr3Data As Byte) As Long
Dim Port As Long, nTimeOut As Long, Mode As Long, Delimiter As Long, Tr2DataLen As Long, Tr3DataLen As Long
Dim Tr2Data(256) As Byte
Dim Tr3Data(256) As Byte
rtn = CT_ReadCard(Port, vbNull, nTimeOut, Mode, Delimiter, Tr2DataLen, Tr2Data(0), Tr3DataLen, Tr3Data(0))
------解决方案--------------------
int __stdcall CT_WriteCard( int nPort, char* BpNo, int nTimeOut, int nMode, int nDelimiter, char *szTr2Data, char *szTr3Data )
------解决方案--------------------
自己再用 VC++ 写 DLL 封装一层,采用 __stdcall 约定调用。常规情况下,VB 不能直接调用 __cdecl 约定的 API。
也可以向原公司索取支持 __stdcall 约定的 DLL 库。
2.2写磁卡
int CT_WriteCard( int nPort,
char* BpNo,
int nTimeOut,
int nMode,
int nDelimiter,
char *szTr2Data,
char *szTr3Data )
2.2.1参数
参数 说明
nPort 0-hid设备,>0串口号
BpNo 转口,NULL-无转口,其他为对应转口
nTimeOut 超时时间,单位秒
nMode 2-读2磁道,3-读3磁道,23-读23磁道
nDelimiter 字符集格式,0-ISO格式,1-IBM格式
szTr2Data 二磁道数据
szTr3Data 三磁道数据
各位大大,以上是某公司读卡器dll封装的函数调用说明,我要在vb里调用,贴下我的代码大家帮忙看下哪有问题(小菜):
Public Declare Function CT_ReadCard Lib "CENT_MsgReader.dll" (ByVal nPort As Integer, ByRef BpNo As Byte, ByVal nTimeOut As Integer, ByVal nMode As Integer, ByVal nDelimiter As Integer, ByVal nTr2DataLen As Integer, ByRef szTr2Data As Byte, ByVal nTr3DataLen As Integer, ByRef szTr3Data As Byte) As Integer
'读磁条卡
Private Function ReadCTCard() As String
Dim rtn As Integer
Dim Port, nTimeOut, Mode, Delimiter, Tr2DataLen, Tr3DataLen As Integer
Dim seflag
nTimeOut = 5
Mode = 23
Delimiter = 0
Tr2DataLen = 255
Tr3DataLen = 255
Dim Tr2Data As Byte
Dim Tr3Data As Byte
seflag = False
For Port = 0 To 4
rtn = CT_ReadCard(Port, vbNull, nTimeOut, Mode, Delimiter, Tr2DataLen, Tr2Data1, Tr3DataLen, Tr3Data1)
If rtn = 0 Then
seflag = True
Exit For
End If
Next Port
Port = 0
If seflag = False Then
MsgBox "读卡失败!" & rtn
ReadCTCard = "读卡失败!" & rtn
Exit Function
End If
MsgBox szTr2Data & "^" & szTr3Data
ReadCTCard = szTr2Data & "^" & szTr3Data
End Function
调试时报DLL调用约定错误,大家能帮忙看一下吗,非常感谢
------解决方案--------------------
你贴出的函数原型是 CT_WriteCard( ) 的,使用的代码却是 CT_ReadCard( ) 的。
这个没太大的“参考价值”呀。
另外一个比较重要的问题,在 C++ 中的 int类型,在 VB6中要用Long才能跟它匹配!
------解决方案--------------------
Public Declare Function CT_ReadCard Lib "CENT_MsgReader.dll" (ByVal nPort As Long, ByRef BpNo As Byte, ByVal nTimeOut As Long, ByVal nMode As Long, ByVal nDelimiter As Long, ByVal nTr2DataLen As Long, ByRef szTr2Data As Byte, ByVal nTr3DataLen As Long, ByRef szTr3Data As Byte) As Long
Dim Port As Long, nTimeOut As Long, Mode As Long, Delimiter As Long, Tr2DataLen As Long, Tr3DataLen As Long
Dim Tr2Data(256) As Byte
Dim Tr3Data(256) As Byte
rtn = CT_ReadCard(Port, vbNull, nTimeOut, Mode, Delimiter, Tr2DataLen, Tr2Data(0), Tr3DataLen, Tr3Data(0))
------解决方案--------------------
int __stdcall CT_WriteCard( int nPort, char* BpNo, int nTimeOut, int nMode, int nDelimiter, char *szTr2Data, char *szTr3Data )
------解决方案--------------------
自己再用 VC++ 写 DLL 封装一层,采用 __stdcall 约定调用。常规情况下,VB 不能直接调用 __cdecl 约定的 API。
也可以向原公司索取支持 __stdcall 约定的 DLL 库。