This is just a regular old Win32 API.
https://docs.microsoft.com/en-us/window ... ishcontext
https://docs.microsoft.com/en-us/window ... streadersw
https://docs.microsoft.com/en-us/window ... tuschangew
I converted the code example from MSDN but i can not test it because i do not have smart cards on my system. I hope it works for you:
Code: Select all
EnableExplicit
#SCARD_SCOPE_USER = 0
#SCARD_SCOPE_TERMINAL = 1
#SCARD_SCOPE_SYSTEM = 2
#SCARD_AUTOALLOCATE = -1
#SCARD_S_SUCCESS = 0
#SCARD_E_NO_READERS_AVAILABLE = $8010002E
;other error codes: https://docs.microsoft.com/en-us/windows/win32/secauthn/authentication-return-values
Prototype.l proto_SCardEstablishContext(dwScope.l, *pvReserved1, *pvReserved2, *phContext)
Prototype.l proto_SCardReleaseContext(*hContext)
Prototype.l proto_SCardListReadersW(*hContext, *mszGroups, *mszReaders, *pcchReaders)
Prototype.l proto_SCardGetStatusChangeW(*hContext, dwTimeout.l, *rgReaderStates, cReaders.l)
Prototype.l proto_SCardFreeMemory(*hContext, *pvMem)
Define hDLL = OpenLibrary(#PB_Any, "Winscard.dll")
If hDLL
Define SCardEstablishContext.proto_SCardEstablishContext = GetFunction(hDLL, "SCardEstablishContext")
Define SCardListReaders.proto_SCardListReadersW = GetFunction(hDLL, "SCardListReadersW")
Define SCardGetStatusChange.proto_SCardGetStatusChangeW = GetFunction(hDLL, "SCardGetStatusChangeW")
Define SCardFreeMemory.proto_SCardFreeMemory = GetFunction(hDLL, "SCardFreeMemory")
Define SCardReleaseContext.proto_SCardReleaseContext = GetFunction(hDLL, "SCardReleaseContext")
If SCardEstablishContext And SCardListReaders And SCardGetStatusChange And SCardFreeMemory And SCardReleaseContext
Define hSC
Define lReturn = SCardEstablishContext(#SCARD_SCOPE_USER, #Null, #Null, @hSC)
If lReturn = #SCARD_S_SUCCESS
Define *pmszReaders
Define cch.l = #SCARD_AUTOALLOCATE
lReturn = SCardListReaders(hSC, #Null, @*pmszReaders, @cch)
Select lReturn
Case #SCARD_E_NO_READERS_AVAILABLE
Debug "Reader is not in groups"
;Take appropriate action.
;...
Case #SCARD_S_SUCCESS
;Do something with the multi string of readers.
;Output the values.
;A double-null terminates the list of values.
Define *pReader.Character = *pmszReaders
While *pReader\c <> '0'
;Display the value.
Define output.s = PeekS(*pReader)
Debug "Reader: " + output.s
;Advance to the next value.
*pReader + StringByteLength(output.s) + SizeOf(Character)
Wend
;Free the memory.
Define lReturn2.l = SCardFreeMemory(hSC, *pmszReaders)
If lReturn2 <> #SCARD_S_SUCCESS
Debug "Failed SCardFreeMemory, error code: 0x" + Hex(lReturn2)
EndIf
Default
Debug "Failed SCardListReaders, error code: 0x" + Hex(lReturn)
EndSelect
Define lReturn3.l = SCardReleaseContext(hSC)
If lReturn3 <> #SCARD_S_SUCCESS
Debug "Failed SCardReleaseContext, error code: 0x" + Hex(lReturn3)
EndIf
Else
Debug "Failed SCardEstablishContext, error code: 0x" + Hex(lReturn)
EndIf
EndIf
EndIf