Disabling PInvokeStackImbalance in Visual Basic Express 2005

 

I have a problem on how to prevent the PInvokeStackImbalance message.

How can I disable this

 



Answer this question

Disabling PInvokeStackImbalance in Visual Basic Express 2005

  • SCulver

     

    Hi,

    I used a DLL file on my smart card reader, the SDK of that hardware used Visual Basic 6 on their SDK.

    I developed an application using Visual Basic Express 2005 and I used the following codes below:

     

    Enum KEYTYPES

     ACR120_LOGIN_KEYTYPE_AA = 0

    ACR120_LOGIN_KEYTYPE_BB = (ACR120_LOGIN_KEYTYPE_AA + 1)

    ACR120_LOGIN_KEYTYPE_FF = (ACR120_LOGIN_KEYTYPE_BB + 1)

    ACR120_LOGIN_KEYTYPE_STORED_A = (ACR120_LOGIN_KEYTYPE_FF + 1)

    ACR120_LOGIN_KEYTYPE_STORED_B = (ACR120_LOGIN_KEYTYPE_STORED_A + 1)

    End Enum

    Public Declare Function ACR120_Login Lib "ACR120.DLL" (ByVal hReader As IntegerByVal stationID As Byte, ByVal sector As Byte, ByVal keyType As KEYTYPES, ByVal storedNo As Long, ByRef pKey As Byte) As Integer

     

     

     

    Private Sub READ_ID_NUMBER()

    Dim sto As Long

    Dim LogType As Byte

    Dim dataRead(0 To 15) As Byte

    Dim dstr As String

    Dim ctr As Integer

    Dim BLCK As Byte

    'Select card

    CARD_SELECT()

    If retCode < 0 Then

    Me.txtData.Text = ""

    Else

    'Set logtype

    LogType = KEYTYPES.ACR120_LOGIN_KEYTYPE_FF

    'Set keys

    pKey(0) = &HFF

    pKey(1) = &HFF

    pKey(2) = &HFF

    pKey(3) = &HFF

    pKey(4) = &HFF

    pKey(5) = &HFF

    'Set sector

    Sec = CInt(4)

    'Log in to sector

     

    The error appears on this line, the LogType variable

     

    retCode = ACR120_Login(rHandle, SID, Sec, LogType, sto, pKey(0))

    'Set block

    BLCK = CByte(0)

    BLCK = Sec * 4 + BLCK

    'Read specified block

    retCode = ACR120_Read(rHandle, SID, BLCK, dataRead(0))

    'Convert bytes read to ASCII

    dstr = ""

    For ctr = 0 To 15

    dstr = dstr + Chr(dataRead(ctr))

    Next

    'Display bytes read

    Me.txtData.Text = (dstr)

    End If

    End Sub

     


  • ShadowedOne

     

    we would need to see the code.

    I've seen it when I've made API calls with the Longs (ala vb6) instead integers.

    I think it means that the stack doesn't look like it's supposed to.

     



  • newone

    Do you have Option Explicit turned on

    Check your project properties.

    Pkey looks very dubious in it's datatyping because it isn't declared. It can be a challenged to pass and array to a DLL expecially one where the compiler has picked a dataype for you.

    Secondly I believe the enun structure will increment thoese values for you.

    Thirdly, you may have to Marshall the interface to this dll.

     

     



  • Disabling PInvokeStackImbalance in Visual Basic Express 2005