Hey. Ive run into a little problem with SCardGetStatusChange function. It might be a silly problem since im new to VBA and programming in general.
This little program of mine already connects to card and is able to read data from it. Now i need the function to wait the insertion of smart card. Thats what i use SCardGetStatusChange for. Im not even sure if its supposed to work in VBA but this is what ive done till now.
Module:
And the Form..
Of course there is alot more code but this should be all which has direct connection to the matter at hand.
context_handle and current_reader_name are stated with these names on earier functions. If im not mistaken INFINITE is defined by -1.
Error is on line connect_to_card_result, where "state" is. Error message - Compile Error: Type mismatch: array or user-defined type expected
Ive tried replacing state with state.dwCurrentState, then only dwCurrentState gets marked. And produces same error.
I hope i didnt miss anything.
Thanks.
This little program of mine already connects to card and is able to read data from it. Now i need the function to wait the insertion of smart card. Thats what i use SCardGetStatusChange for. Im not even sure if its supposed to work in VBA but this is what ive done till now.
Module:
Code:
[COLOR=#000080]Public[/COLOR] Type SCARD_READERSTATE
szReader [COLOR=#000080]As[/COLOR] [COLOR=#000080]String[/COLOR]
pvUserData [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR]
dwCurrentState [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR]
dwEventState [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR]
cbAtr [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR]
rgbAtr(0 [COLOR=#000080]To[/COLOR] 35) [COLOR=#000080]As[/COLOR] [COLOR=#000080]Byte[/COLOR]
[COLOR=#000080]End[/COLOR] Type
[COLOR=#000080]Public[/COLOR] [COLOR=#000080]Declare[/COLOR] [COLOR=#000080]Function[/COLOR] SCardGetStatusChange Lib "winscard.dll" Alias "SCardGetStatusChangeA" ( _
[COLOR=#000080]ByVal[/COLOR] hContext [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR], _
[COLOR=#000080]ByVal[/COLOR] dwTimeout [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR], _
[COLOR=#000080]ByRef[/COLOR] rgReaderStates() [COLOR=#000080]As[/COLOR] SCARD_READERSTATE, _
[COLOR=#000080]ByVal[/COLOR] cReaders [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR] _
) [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR]
And the Form..
Code:
Private Function connect_to_card() As Boolean
Dim state As SCARD_READSTATE
state.szReader = current_reader_name
state.dwCurrentState = SCARD_STATE_EMPTY
connect_to_card_result = SCardGetStatusChange(context_handle, -1, state, 1)
End Function
Of course there is alot more code but this should be all which has direct connection to the matter at hand.
context_handle and current_reader_name are stated with these names on earier functions. If im not mistaken INFINITE is defined by -1.
Error is on line connect_to_card_result, where "state" is. Error message - Compile Error: Type mismatch: array or user-defined type expected
Ive tried replacing state with state.dwCurrentState, then only dwCurrentState gets marked. And produces same error.
I hope i didnt miss anything.
Thanks.