2012-04-03 64 views
1

有誰知道如何在Visual Basic中創建結構?如何在vb 2008中創建sturucture

例如:

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 

我使用Microsoft Visual Basic 2008

回答

0

你聲明的結構是這樣的:

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 

然而,這看起來不會對你來說足夠好。您需要添加幾個attributes以更精確地控制結構的佈局,以實現該方法的適當marshalling。我不熟悉這裏的具體方法,但http://pinvoke.net可能會幫助您找到right way to declare this method以及the right way to build the structure

pinvoke.net網站是基於wiki的,因此請務必向那些追隨您的人添加您學到的任何內容。網站上的大部分內容都是用C#編寫的,但如果您瞭解屬性語法,那麼翻譯通常非常簡單。

0

您需要的SCARD_READERSTATE結構從SCardGetStatusChange庫 「winscard.dll」 的宣言,像這樣分離:

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