vb6.0 调用dll问题
SmartCom411SFJ.dll 中,有 int ReadCard(int ComPort, int CardNumLength,unsigned char *CardNum,unsigned char *CardNum1,unsigned char *Password,unsigned char *CardID,unsigned char *Name ,int &Money)
在VB 这样声明
Public Declare Function ReadCard Lib "C:\WINDOWS\SYSTEM32\SmartCom411SFJ.dll" (ByVal ComPort As Long, ByVal CardNumLength As Long, ByRef CardNum As Byte, ByRef CardNum1 As Byte, ByRef Password As Byte, ByRef CardID As Byte, ByVal Name As String, ByRef Money As Integer) As Long
能够正确返回CardNum,CardNum1值,其他的要么显示为空白,要么返回值不对,请高手指点一下,谢谢!
[最优解释]
Public Declare Function SMT_ReadCard Lib "C:\WINDOWS\SYSTEM32\SmartCom411SFJ.dll" (ByVal ComPort As Long, ByVal CardNumLength As Long, ByRef CardNum As Byte, ByRef
CardNum1 As Byte, ByRef Password As Byte, ByRef CardID As Byte, ByRef Name As Byte, ByRef Money As Long) As Long
Dim CardNumLength As Long
' 出口参数:
Dim CardNum(15) As Byte '显示卡号(ASCII码),显示卡号长度等于CardNumLength
Dim CardNum1(7) As Byte '7字节交易卡号,不足7位前补'0 '(ASCII码)
Dim Password(10) As Byte '字节个人密码(密文, ASCII码)
Dim CardID(4) As Byte '4字节卡序列号(HEX)
Dim bName(7) As Byte
Dim Money As Long '卡余额,以分为单位
Dim RTV As Long
CardNumLength = 15
RTV = ReadCard(ComPort, CardNumLength, CardNum(0), CardNum1(0), Password(0), CardID(0), bName(0), Money)
Text2.Text = StrConv(bName, vbUnicode)
Text3.Text = StrConv(CardNum, vbUnicode)
Text4.Text = StrConv(CardID, vbUnicode)
Text5.Text = StrConv(CardNum1, vbUnicode)
Text6.Text = Money / 100
[其他解释]
SmartCom411SFJ.dll 中,有 int ReadCard(int ComPort, int CardNumLength,unsigned char *CardNum,unsigned char *CardNum1,unsigned char *Password,unsigned char *CardID,unsigned char *Name ,int &Money)
在VB 这样声明
Public Declare Function ReadCard Lib "C:\WINDOWS\SYSTEM32\SmartCom411SFJ.dll" (ByVal ComPort As Long, ByVal CardNumLength As Long, Byval CardNum As string, Byval CardNum1 As string, Byval Password As string, Byval CardID As string, ByVal Name As String, ByRef Money As Integer) As Long
[其他解释]
我的方法运行结果如下
===============================================================================
Public Declare Function SMT_ReadCard Lib "C:\WINDOWS\SYSTEM32\SmartCom411SFJ.dll" (ByVal ComPort As Long, ByVal CardNumLength As Long, ByRef CardNum As Byte, ByRef
CardNum1 As Byte, ByRef Password As Byte, ByRef CardID As Byte, ByVal Name As String, ByRef Money As Integer) As Long
Dim CardNumLength As Long
' 出口参数:
Dim CardNum(15) As Byte '显示卡号(ASCII码),显示卡号长度等于CardNumLength
Dim CardNum1(7) As Byte '7字节交易卡号,不足7位前补'0 '(ASCII码)
Dim Password(10) As Byte '字节个人密码(密文, ASCII码)
Dim CardID(4) As Byte '4字节卡序列号(HEX)
Dim Name As String * 8 '8字节姓名(ASCII码)
Dim Money As Integer '卡余额,以分为单位
Dim RTV As Long
CardNumLength = 15
RTV = ReadCard(ComPort, CardNumLength, CardNum(0), CardNum1(0), Password(0), CardID(0), Name, Money)
Select Case RTV
Case 0
Text2.Text = Name 返回空白 ?
Text3.Text = StrConv(CardNum, vbUnicode) 返回值 正确
Text4.Text = StrConv(CardID, vbUnicode) 返回空白 ?
Text5.Text = StrConv(CardNum1, vbUnicode) 返回值 正确
Text6.Text = Money / 100 返回值 123.45 实际是23.49 不正确
=====================================================================================
按楼主方法,运行结果与上面我的结果基本相同,不知问题出在什么地方?
=====================================================================================
Public Declare Function SMT_ReadCard Lib "C:\WINDOWS\SYSTEM32\SmartCom411SFJ.dll" (ByVal ComPort As Long, ByVal CardNumLength As Long, ByVal CardNum As String, ByVal
CardNum1 As String, ByVal Password As String, ByVal CardID As String, ByVal Name As String, ByRef Money As Integer) As Long
Dim CardNum As String * 15 '显示卡号(ASCII码),显示卡号长度等于CardNumLength
Dim CardNum1 As String * 7 '7字节交易卡号,不足7位前补'0 '(ASCII码)
Dim Password As String * 6 '6字节个人密码(密文, ASCII码)
Dim CardID As String * 4 '4字节卡序列号(HEX)
Dim Name As String * 8 '8字节姓名(ASCII码)
Dim Money As Integer '卡余额,以分为单位
CardNumLength = 15
RTV = SMT_ReadCard(ComPort, CardNumLength, CardNum, CardNum1, Password, CardID, Name, Money)
Text2.Text = Name 返回一个数字,应该是汉字 ?
Text3.Text = CardNum 返回值 正确
Text4.Text = CardID 返回空白 ?
Text5.Text = CardNum1 返回值 正确
Text6.Text = Money / 100 返回值 123.45 实际是23.49 不正确
[其他解释]
按照楼主方法,其结果如下:
Text2.Text = Name 返回值为空白,应该是汉字才对 ?
Text3.Text = CardNum 返回值 正确
Text4.Text = CardID 返回空白 ?
Text5.Text = CardNum1 返回值 正确
Text6.Text = Money / 100 返回值 31580.73 实际是23.49 不正确
问题依然存在,没用返回汉字人名,金额money也不对,不知问题出现在哪儿?
[其他解释]
而且很奇怪:读不同的两张卡,显示的金额一个是31580.73,另一个是31580.72,而实际上两张卡内金额是不一样的,一个为23.49,另外一个为0
[其他解释]
您好!在吗?我想请教您一个问题好吗?C++程序是这样调用dll: int &type,unsigned char*);
typedef UINT (CALLBACK* PReadCard)(int ComPort,unsigned char *CardNum,
unsigned char *CardNum1,
unsigned char *Password,
unsigned char *CardID,
unsigned char *Name,
int &Money);
unsigned char ucCardNum[256];
unsigned char ucCardNum1[256];
unsigned char ucReserved[256];
unsigned char ucCardID[256];
unsigned char ucName[256];
int nMoney;
memset(ucCardNum,0x00,sizeof ucCardNum);
retCode = ReadCard(portno,ucCardNum,ucCardNum1,ucReserved,ucCardID,ucName,nMoney);//注意nMoney使用
我用VB是这样写的:
Public Declare Function ReadCard Lib "SmartCom411SFJ.dll" (ByVal comport As Long, ByRef cardNum As Byte, ByRef cardNum1 As Byte, ByRef Password As Byte, ByRef cardID As Byte, ByRef Name As Byte, ByVal money As Long) As Long
Dim cardNum(256) As Byte
Dim cardNum1(256) As Byte
Dim Password(256) As Byte
Dim cardID(256) As Byte
Dim Name(256) As Byte
Dim money As Long
back = ReadCard(comport, cardNum(0), cardNum1(0), Password(0), cardID(0), Name(0), money)
MsgBox back
MsgBox StrConv(cardNum, vbUnicode)
但是程序运行自动关闭。请问我的定义错误了吗?谢