2012-04-03 4 views
1

Est-ce que quelqu'un sait comment créer une structure dans Visual Basic?comment créer une structure en vb 2008

Par exemple:

Public SCARD_READERSTATE() 
    Dim szReader As String 'reader name 
    Dim pvUserData As Long 'user defined data 
    Dim dwCurrentState As Long 'current state of reader at time of call 
    Dim dwEventState As Long 'state of reader after state change 
    Dim cbAtr As Long 'Number of bytes in the returned ATR 
    Dim rgbAtr(0 To 35) As Byte 'Atr of inserted card, (extra alignment bytes) 

    Public Declare Function SCardGetStatusChange Lib "winscard.dll" Alias "SCardGetStatusChangeA" (_ 
     ByVal hContext As Long, _ 
     ByVal dwTimeout As Long, _ 
     ByRef rgReaderStates() As SCARD_READERSTATE, _ 
     ByVal cReaders As Long _ 
     ) As Long 

J'utilise Microsoft Visual Basic 2008.

Répondre

0

Vous déclarez une structure comme ceci:

Public Structure SCARD_READERSTATE 
    Public szReader As String 'reader name 
    Public pvUserData As Long 'user defined data 
    Public dwCurrentState As Long 'current state of reader at time of call 
    Public dwEventState As Long 'state of reader after state change 
    Public cbAtr As Long 'Number of bytes in the returned ATR 
    Public rgbAtr(35) As Byte 'Atr of inserted card, (extra alignment bytes) 

    Public Declare Function SCardGetStatusChange Lib "winscard.dll" Alias "SCardGetStatusChangeA" (_ 
     ByVal hContext As Long, _ 
     ByVal dwTimeout As Long, _ 
     ByRef rgReaderStates() As SCARD_READERSTATE, _ 
     ByVal cReaders As Long _ 
     ) As Long 
End Structure 

Cependant, il semble que ce ne sera pas sois assez bon pour toi. Vous aurez besoin d'ajouter quelques attributes pour contrôler plus précisément la disposition de la structure afin d'obtenir le marshalling approprié pour la méthode. Je ne suis pas familier avec la méthode spécifique ici, mais http://pinvoke.net peut vous aider à trouver le right way to declare this method ainsi que the right way to build the structure. Le site pinvoke.net est basé sur un wiki, alors assurez-vous d'ajouter tout ce que vous apprendrez à ces pages pour ceux qui viendront après vous. La plupart des éléments du site sont actuellement en C#, mais si vous comprenez la syntaxe de l'attribut, la traduction est généralement très simple.

0

Vous devez séparer la structure de SCARD_READERSTATE de la SCardGetStatusChange Lib déclaration "de winscard.dll" comme ceci:

Public Structure SCARD_READERSTATE 
    Public szReader As String 'reader name 
    Public pvUserData As Long 'user defined data 
    Public dwCurrentState As Long 'current state of reader at time of call 
    Public dwEventState As Long 'state of reader after state change 
    Public cbAtr As Long 'Number of bytes in the returned ATR 
    Public rgbAtr(35) As Byte 'Atr of inserted card, (extra alignment bytes) 
End Structure 

Public Declare Function SCardGetStatusChange Lib "winscard.dll" Alias "SCardGetStatusChangeA" (_ 
     ByVal hContext As Long, _ 
     ByVal dwTimeout As Long, _ 
     ByRef rgReaderStates() As SCARD_READERSTATE, _ 
     ByVal cReaders As Long _ 
     ) As Long