Hi,
I'm rewriting an old VB6 app of mine in VB2008. All has been going well with
calls to winscard.dll, until I needed to send an array of bytes as part of a
structure. When using a winscard trace, I can see that the bytes in the
array suddenly become nonsense, whereas I know that what I called the DLL
with was good.
I think I need to do something along the lines of MarshalAs, but I haven't
the first clue where to start. Any assistance would be greatly appreciated.
Snippets of code follow (the actual call causing trouble is on the
"lResult=" line).
Thanks
John
EMV_Fns.vb
==========
Public StructC3 As APDURec
..
..
..
Public Function Case3APDU(ByVal CLA As Int32, ByVal INS As Int32, ByVal
P1 As Int32, ByVal P2 As Int32, ByVal Lc As Int32, ByVal Data As String) As
ResponseStruct
Dim LoadByte As Integer
StructC3.bCLA = CLA
StructC3.bINS = INS
StructC3.bP1 = P1
StructC3.bP2 = P2
StructC3.bP3 = Lc
ReDim StructC3.Data(L c - 1)
For LoadByte = 0 To (Len(Data) / 2) - 1
StructC3.Data(L oadByte) = Val("&H" + Mid(Data, 1 + (LoadByte *
2), 2))
Next LoadByte
SendBuffLen = &H5 + Lc
RcvBuffLen = &HFF
lResult = PCSC.SCardTrans mit(hCard, 0, StructC3, SendBuffLen, 0,
ReceiveBuff(0), RcvBuffLen)
If lResult <SCARD_S_SUCCES S Then
DummyByte = PcscError("Case 3-SCardTransmit", lResult)
End If
Case3APDU = ProcessResponse (ReceiveBuff, RcvBuffLen, True, 8, 16,
True)
End Function
PCSC_Fns.vb
===========
Public Structure APDURec
Dim bCLA As Byte
Dim bINS As Byte
Dim bP1 As Byte
Dim bP2 As Byte
Dim bP3 As Byte
Dim Data() As Byte
Dim IsSend As Boolean
End Structure
..
..
..
Declare Ansi Function SCardTransmit Lib "WinScard.d ll" ( _
ByVal hCard As Int32, ByVal pioSendRequest As Int32, _
ByRef sendbuff As APDURec, ByVal SendBuffLen As Int32, _
ByVal pioRecvRequest As Int32, ByRef RecvBuff As Byte, _
ByRef RecvBuffLen As Int32) As Int32
I'm rewriting an old VB6 app of mine in VB2008. All has been going well with
calls to winscard.dll, until I needed to send an array of bytes as part of a
structure. When using a winscard trace, I can see that the bytes in the
array suddenly become nonsense, whereas I know that what I called the DLL
with was good.
I think I need to do something along the lines of MarshalAs, but I haven't
the first clue where to start. Any assistance would be greatly appreciated.
Snippets of code follow (the actual call causing trouble is on the
"lResult=" line).
Thanks
John
EMV_Fns.vb
==========
Public StructC3 As APDURec
..
..
..
Public Function Case3APDU(ByVal CLA As Int32, ByVal INS As Int32, ByVal
P1 As Int32, ByVal P2 As Int32, ByVal Lc As Int32, ByVal Data As String) As
ResponseStruct
Dim LoadByte As Integer
StructC3.bCLA = CLA
StructC3.bINS = INS
StructC3.bP1 = P1
StructC3.bP2 = P2
StructC3.bP3 = Lc
ReDim StructC3.Data(L c - 1)
For LoadByte = 0 To (Len(Data) / 2) - 1
StructC3.Data(L oadByte) = Val("&H" + Mid(Data, 1 + (LoadByte *
2), 2))
Next LoadByte
SendBuffLen = &H5 + Lc
RcvBuffLen = &HFF
lResult = PCSC.SCardTrans mit(hCard, 0, StructC3, SendBuffLen, 0,
ReceiveBuff(0), RcvBuffLen)
If lResult <SCARD_S_SUCCES S Then
DummyByte = PcscError("Case 3-SCardTransmit", lResult)
End If
Case3APDU = ProcessResponse (ReceiveBuff, RcvBuffLen, True, 8, 16,
True)
End Function
PCSC_Fns.vb
===========
Public Structure APDURec
Dim bCLA As Byte
Dim bINS As Byte
Dim bP1 As Byte
Dim bP2 As Byte
Dim bP3 As Byte
Dim Data() As Byte
Dim IsSend As Boolean
End Structure
..
..
..
Declare Ansi Function SCardTransmit Lib "WinScard.d ll" ( _
ByVal hCard As Int32, ByVal pioSendRequest As Int32, _
ByRef sendbuff As APDURec, ByVal SendBuffLen As Int32, _
ByVal pioRecvRequest As Int32, ByRef RecvBuff As Byte, _
ByRef RecvBuffLen As Int32) As Int32
Comment