WinScard.dll and VB2008

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Whitworth

    #1

    WinScard.dll and VB2008

    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


  • John Whitworth

    #2
    Re: WinScard.dll and VB2008


    "John Whitworth" <sexyjw@gEEEEEE EEEEEEEEEEmail. comwrote in message
    news:OlG1s4YFJH A.3996@TK2MSFTN GP03.phx.gbl...
    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.
    As suggested in an old message on another forum, I have tried using
    System.Text.Str ingbuilder for this, but it fails with an error saying that a
    normal string might work. It doesn't! :-(

    Thx

    John

    Comment

    • John Whitworth

      #3
      Re: WinScard.dll and VB2008


      "John Whitworth" <sexyjw@gEEEEEE EEEEEEEEEEmail. comwrote in message
      news:OlG1s4YFJH A.3996@TK2MSFTN GP03.phx.gbl...
      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've gone some way to solving this now. I've set up a new ByteStream
      function, which just copies everything that was in an APDUrec structure into
      a Byte() field. This then seems to pass into the DLL OK.

      Thanks

      John

      Comment

      Working...