⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scardapi.bas

📁 IC卡讀取系統原始程式
💻 BAS
📖 第 1 页 / 共 3 页
字号:
Attribute VB_Name = "SCardAPI"
Public Type SCARD_T1_RESPONSE
    ' Status return code
    SW1 As Byte
    SW2 As Byte
    ' Process return data
    bytRData() As Byte
    ' Process return value
    bytRDataLen As Long
    bytRetValue As Byte
End Type

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Declarations of the Windows Smart Card API
'
' Note: variable names, such as those in typedef's and function
'       parameters, have been retained from the C++ API definition
'
Public Const lngNull As Long = 0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Defines

' The context is a user context, and any
' database operations are performed within the
' domain of the user.
Public Const SCARD_SCOPE_USER As Long = 0

' The context is that of the current terminal,
' and any database operations are performed
' within the domain of that terminal.  (The
' calling application must have appropriate
' access permissions for any database actions.)
Public Const SCARD_SCOPE_TERMINAL As Long = 1

' The context is the system context, and any
' database operations are performed within the
' domain of the system.  (The calling
' application must have appropriate access
' permissions for any database actions.)
Public Const SCARD_SCOPE_SYSTEM As Long = 2

' Flag to have Resource Manager allocate buffer space
Public Const SCARD_AUTOALLOCATE As Long = -1

' Strings for managing the Smart Card Database
Public Const SCARD_ALL_READERS     As String = "SCard$AllReaders" + vbNullChar + vbNullChar
Public Const SCARD_DEFAULT_READERS As String = "SCard$DefaultReaders" + vbNullChar + vbNullChar
Public Const SCARD_LOCAL_READERS   As String = "SCard$LocalReaders" + vbNullChar + vbNullChar
Public Const SCARD_SYSTEM_READERS  As String = "SCard$SystemReaders" + vbNullChar + vbNullChar

' Primary Provider Id
Public Const SCARD_PROVIDER_PRIMARY As Long = 1
' Crypto Service Provider Id
Public Const SCARD_PROVIDER_CSP     As Long = 2

' There is no active protocol
Public Const SCARD_PROTOCOL_UNDEFINED   As Long = 0

' T=0 is the active protocol
Public Const SCARD_PROTOCOL_T0          As Long = 1

' T=1 is the active protocol
Public Const SCARD_PROTOCOL_T1          As Long = 2

' Raw is the active protocol.
Public Const SCARD_PROTOCOL_RAW         As Long = &H10000

' This is the mask of ISO defined transmission protocols
Public Const SCARD_PROTOCOL_Tx          As Long = SCARD_PROTOCOL_T0 Or SCARD_PROTOCOL_T1

' Use the default transmission parameters / card clock freq.
Public Const SCARD_PROTOCOL_DEFAULT     As Long = &H80000000

' Use optimal transmission parameters / card clock freq.
' Since using the optimal parameters is the default case no bit is defined to be 1
Public Const SCARD_PROTOCOL_OPTIMAL     As Long = &H0

' This application is not willing to share this
' card with other applications.
Public Const SCARD_SHARE_EXCLUSIVE      As Long = 1

' This application is willing to share this
' card with other applications.
Public Const SCARD_SHARE_SHARED         As Long = 2

' This application demands direct control of
' the reader, so it is not available to other
' applications.
Public Const SCARD_SHARE_DIRECT         As Long = 3

' Don't do anything special on close
Public Const SCARD_LEAVE_CARD           As Long = 0

' Reset the card on close
Public Const SCARD_RESET_CARD           As Long = 1

' Power down the card on close
Public Const SCARD_UNPOWER_CARD         As Long = 2

' Eject the card on close
Public Const SCARD_EJECT_CARD           As Long = 3

' Nothing bigger than this from getAttr
Public Const MAXIMUM_ATTR_STRING_LENGTH As Long = 32
' Limit the readers on the system
Public Const MAXIMUM_SMARTCARD_READERS  As Long = 10

' This value implies the driver is unaware
' of the current state of the reader.
Public Const SCARD_UNKNOWN              As Long = 0
' This value implies there is no card in
' the reader.
Public Const SCARD_ABSENT               As Long = 1
' This value implies there is a card is
' present in the reader, but that it has
' not been moved into position for use.
Public Const SCARD_PRESENT              As Long = 2
' This value implies there is a card in the
'  reader in position for use.  The card is
'  not powered.
Public Const SCARD_SWALLOWED            As Long = 3
' This value implies there is power is
' being provided to the card, but the
' Reader Driver is unaware of the mode of
' the card.
Public Const SCARD_POWERED              As Long = 4
' This value implies the card has been
' reset and is awaiting PTS negotiation.
Public Const SCARD_NEGOTIABLE           As Long = 5
' This value implies the card has been
' reset and specific communication
' protocols have been established.
Public Const SCARD_SPECIFIC             As Long = 6

' Ioctl parameters for IOCTL_SMARTCARD_POWER
' Power down the card.
Public Const SCARD_POWER_DOWN           As Long = 0
' Cycle power and reset the card.
Public Const SCARD_COLD_RESET           As Long = 1
' Force a reset on the card.
Public Const SCARD_WARM_RESET           As Long = 2

' Smartcard IOCTL class
Public Const FILE_DEVICE_SMARTCARD      As Long = &H310000

' Reader action IOCTLs
Public Const IOCTL_SMARTCARD_POWER           As Long = FILE_DEVICE_SMARTCARD + &H4
Public Const IOCTL_SMARTCARD_GET_ATTRIBUTE   As Long = FILE_DEVICE_SMARTCARD + &H8
Public Const IOCTL_SMARTCARD_SET_ATTRIBUTE   As Long = FILE_DEVICE_SMARTCARD + &HC
Public Const IOCTL_SMARTCARD_CONFISCATE      As Long = FILE_DEVICE_SMARTCARD + &H10
Public Const IOCTL_SMARTCARD_TRANSMIT        As Long = FILE_DEVICE_SMARTCARD + &H14
Public Const IOCTL_SMARTCARD_EJECT           As Long = FILE_DEVICE_SMARTCARD + &H18
Public Const IOCTL_SMARTCARD_SWALLOW         As Long = FILE_DEVICE_SMARTCARD + &H1C
Public Const IOCTL_SMARTCARD_IS_PRESENT      As Long = FILE_DEVICE_SMARTCARD + &H28
Public Const IOCTL_SMARTCARD_IS_ABSENT       As Long = FILE_DEVICE_SMARTCARD + &H2C
Public Const IOCTL_SMARTCARD_SET_PROTOCOL    As Long = FILE_DEVICE_SMARTCARD + &H30
Public Const IOCTL_SMARTCARD_GET_STATE       As Long = FILE_DEVICE_SMARTCARD + &H38
Public Const IOCTL_SMARTCARD_GET_LAST_ERROR  As Long = FILE_DEVICE_SMARTCARD + &H3C

' Vendor information definitions - classes
Public Const SCARD_CLASS_VENDOR_INFO    As Long = &H10000
' Communication definitions
Public Const SCARD_CLASS_COMMUNICATIONS As Long = &H20000
' Protocol definitions
Public Const SCARD_CLASS_PROTOCOL       As Long = &H30000
' Power Management definitions
Public Const SCARD_CLASS_POWER_MGMT     As Long = &H40000
' Security Assurance definitions
Public Const SCARD_CLASS_SECURITY       As Long = &H50000
' Mechanical characteristic definitions
Public Const SCARD_CLASS_MECHANICAL     As Long = &H60000
' Vendor specific definitions
Public Const SCARD_CLASS_VENDOR_DEFINED As Long = &H70000
' Interface Device Protocol options
Public Const SCARD_CLASS_IFD_PROTOCOL   As Long = &H80000
' ICC State specific definitions
Public Const SCARD_CLASS_ICC_STATE      As Long = &H90000
' System-specific definitions
Public Const SCARD_CLASS_SYSTEM         As Long = &H7FFF0000
' Vendor information definitions - items
Public Const SCARD_ATTR_VENDOR_NAME              As Long = SCARD_CLASS_VENDOR_INFO + &H100
Public Const SCARD_ATTR_VENDOR_IFD_TYPE          As Long = SCARD_CLASS_VENDOR_INFO + &H101
Public Const SCARD_ATTR_VENDOR_IFD_VERSION       As Long = SCARD_CLASS_VENDOR_INFO + &H102
Public Const SCARD_ATTR_VENDOR_IFD_SERIAL_NO     As Long = SCARD_CLASS_VENDOR_INFO + &H103
Public Const SCARD_ATTR_CHANNEL_ID               As Long = SCARD_CLASS_COMMUNICATIONS + &H110
Public Const SCARD_ATTR_PROTOCOL_TYPES           As Long = SCARD_CLASS_PROTOCOL + &H120
Public Const SCARD_ATTR_DEFAULT_CLK              As Long = SCARD_CLASS_PROTOCOL + &H121
Public Const SCARD_ATTR_MAX_CLK                  As Long = SCARD_CLASS_PROTOCOL + &H122
Public Const SCARD_ATTR_DEFAULT_DATA_RATE        As Long = SCARD_CLASS_PROTOCOL + &H123
Public Const SCARD_ATTR_MAX_DATA_RATE            As Long = SCARD_CLASS_PROTOCOL + &H124
Public Const SCARD_ATTR_MAX_IFSD                 As Long = SCARD_CLASS_PROTOCOL + &H125
Public Const SCARD_ATTR_POWER_MGMT_SUPPORT       As Long = SCARD_CLASS_POWER_MGMT + &H131
Public Const SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE As Long = SCARD_CLASS_SECURITY + &H140
Public Const SCARD_ATTR_USER_AUTH_INPUT_DEVICE   As Long = SCARD_CLASS_SECURITY + &H142
Public Const SCARD_ATTR_CHARACTERISTICS          As Long = SCARD_CLASS_MECHANICAL + &H150
Public Const SCARD_ATTR_CURRENT_PROTOCOL_TYPE    As Long = SCARD_CLASS_IFD_PROTOCOL + &H201
Public Const SCARD_ATTR_CURRENT_CLK              As Long = SCARD_CLASS_IFD_PROTOCOL + &H202
Public Const SCARD_ATTR_CURRENT_F                As Long = SCARD_CLASS_IFD_PROTOCOL + &H203
Public Const SCARD_ATTR_CURRENT_D                As Long = SCARD_CLASS_IFD_PROTOCOL + &H204
Public Const SCARD_ATTR_CURRENT_N                As Long = SCARD_CLASS_IFD_PROTOCOL + &H205
Public Const SCARD_ATTR_CURRENT_W                As Long = SCARD_CLASS_IFD_PROTOCOL + &H206
Public Const SCARD_ATTR_CURRENT_IFSC             As Long = SCARD_CLASS_IFD_PROTOCOL + &H207
Public Const SCARD_ATTR_CURRENT_IFSD             As Long = SCARD_CLASS_IFD_PROTOCOL + &H208
Public Const SCARD_ATTR_CURRENT_BWT              As Long = SCARD_CLASS_IFD_PROTOCOL + &H209
Public Const SCARD_ATTR_CURRENT_CWT              As Long = SCARD_CLASS_IFD_PROTOCOL + &H20A
Public Const SCARD_ATTR_CURRENT_EBC_ENCODING     As Long = SCARD_CLASS_IFD_PROTOCOL + &H20B
Public Const SCARD_ATTR_EXTENDED_BWT             As Long = SCARD_CLASS_IFD_PROTOCOL + &H20C
Public Const SCARD_ATTR_ICC_PRESENCE             As Long = SCARD_CLASS_ICC_STATE + &H300
Public Const SCARD_ATTR_ICC_INTERFACE_STATUS     As Long = SCARD_CLASS_ICC_STATE + &H301
Public Const SCARD_ATTR_CURRENT_IO_STATE         As Long = SCARD_CLASS_ICC_STATE + &H302
Public Const SCARD_ATTR_ATR_STRING               As Long = SCARD_CLASS_ICC_STATE + &H303
Public Const SCARD_ATTR_ICC_TYPE_PER_ATR         As Long = SCARD_CLASS_ICC_STATE + &H304
Public Const SCARD_ATTR_ESC_RESET                As Long = SCARD_CLASS_VENDOR_DEFINED + &HA000
Public Const SCARD_ATTR_ESC_CANCEL               As Long = SCARD_CLASS_VENDOR_DEFINED + &HA003
Public Const SCARD_ATTR_ESC_AUTHREQUEST          As Long = SCARD_CLASS_VENDOR_DEFINED + &HA005
Public Const SCARD_ATTR_MAXINPUT                 As Long = SCARD_CLASS_VENDOR_DEFINED + &HA007
Public Const SCARD_ATTR_DEVICE_UNIT              As Long = SCARD_CLASS_SYSTEM + &H1
Public Const SCARD_ATTR_DEVICE_IN_USE            As Long = SCARD_CLASS_SYSTEM + &H2
Public Const SCARD_ATTR_DEVICE_FRIENDLY_NAME_A   As Long = SCARD_CLASS_SYSTEM + &H3
Public Const SCARD_ATTR_DEVICE_SYSTEM_NAME_A     As Long = SCARD_CLASS_SYSTEM + &H4
Public Const SCARD_ATTR_DEVICE_FRIENDLY_NAME_W   As Long = SCARD_CLASS_SYSTEM + &H5
Public Const SCARD_ATTR_DEVICE_SYSTEM_NAME_W     As Long = SCARD_CLASS_SYSTEM + &H6
Public Const SCARD_ATTR_SUPRESS_T1_IFS_REQUEST   As Long = SCARD_CLASS_SYSTEM + &H7

' types for tracking cards within readers

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

' The application is unaware of the current state, and would like to
' know.  The use of this value results in an immediate return
' from state transition monitoring services.  This is represented by
' all bits set to zero.
Public Const SCARD_STATE_UNAWARE     As Long = &H0

' The application requested that this reader be ignored.  No other
' bits will be set.
Public Const SCARD_STATE_IGNORE      As Long = &H1

' This implies that there is a difference between the state
' believed by the application, and the state known by the Service
' Manager.  When this bit is set, the application may assume a
' significant state change has occurred on this reader.
Public Const SCARD_STATE_CHANGED     As Long = &H2

' This implies that the given reader name is not recognized by
' the Service Manager.  If this bit is set, then SCARD_STATE_CHANGED
' and SCARD_STATE_IGNORE will also be set.
Public Const SCARD_STATE_UNKNOWN     As Long = &H4

' This implies that the actual state of this reader is not
' available.  If this bit is set, then all the following bits are clear.
Public Const SCARD_STATE_UNAVAILABLE As Long = &H8

' This implies that there is not card in the reader.  If this bit
' is set, all the following bits will be clear.
Public Const SCARD_STATE_EMPTY       As Long = &H10

' This implies that there is a card in the reader.
Public Const SCARD_STATE_PRESENT     As Long = &H20

' This implies that there is a card in the reader with an ATR
' matching one of the target cards.  If this bit is set,
' SCARD_STATE_PRESENT will also be set.  This bit is only returned
' on the SCardLocateCard() service.
Public Const SCARD_STATE_ATRMATCH    As Long = &H40

' This implies that the card in the reader is allocated for exclusive
' use by another application.  If this bit is set,
' SCARD_STATE_PRESENT will also be set.
Public Const SCARD_STATE_EXCLUSIVE   As Long = &H80

' This implies that the card in the reader is in use by one or more'
' other applications, but may be connected to in shared mode.  If
' this bit is set, SCARD_STATE_PRESENT will also be set.
Public Const SCARD_STATE_INUSE       As Long = &H100

' This implies that the card in the reader is unresponsive or not
' supported by the reader or software.
Public Const SCARD_STATE_MUTE        As Long = &H200

' This implies that the card in the reader has not been powered up.
Public Const SCARD_STATE_UNPOWERED   As Long = &H400

' types for providing access to the I/O capabilities of the reader drivers

' I/O request control
Type SCARD_IO_REQUEST
    ' Protocol identifier
    dwProtocol As Long
    ' Protocol Control Information Length
    dbPciLength As Long
End Type

' T=0 command
Type SCARD_T0_Command
    ' the instruction class
    bCla As Byte
    ' the instruction code within the instruction class
    bIns As Byte
    ' first parameter of the function
    bP1 As Byte
    ' second parameter of the function
    bP2 As Byte
    ' size of the I/O transfer
    bP3 As Byte
End Type

' T=0 request
Type SCARD_T0_REQUEST
    ' I/O request control
    ioRequest As SCARD_IO_REQUEST
    ' first return code from the instruction
    bSw1 As Byte
    ' second return code from the instruction
    bSw2 As Byte
    ' I/O command
    CmdBytes As SCARD_T0_Command
End Type

' T=1 request
Type SCARD_T1_REQUEST
    ' I/O request control
    ioRequest As SCARD_IO_REQUEST
End Type

' smart card dialog definitions

' show UI only if required to select card
Public Const SC_DLG_MINIMAL_UI      As Long = 1

' do not show UI in any case
Public Const SC_DLG_NO_UI           As Long = 2

' show UI in every case
Public Const SC_DLG_FORCE_UI        As Long = 4

' dialog error returns
Public Const SCERR_NOCARDNAME       As Long = &H4000
Public Const SCERR_NOGUIDS          As Long = &H8000


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Error definitions of the Windows Smart Card API
''
'
'
'' success result indicated by API call
'Public Const NO_ERROR As Long = 0
'Public Const SCARD_S_SUCCESS As Long = NO_ERROR
'
''//
''//  Values are 32 bit values layed out as follows:
''//
''//   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
''//   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
''//  +---+-+-+-----------------------+-------------------------------+
''//  |Sev|C|R|     Facility          |               Code            |
''//  +---+-+-+-----------------------+-------------------------------+
''//
''//  where
''//
''//      Sev - is the severity code
''//
''//          00 - Success
''//          01 - Informational
''//          10 - Warning
''//          11 - Error
''//
''//      C - is the Customer code flag
''//
''//      R - is a reserved bit
''//
''//      Facility - is the facility code
''//
''//      Code - is the facility's status code
''//
''//
''// Define the facility codes
''//
''Public Const FACILITY_SYSTEM                  0x0
''Public Const FACILITY_SCARD                   0x10
'
'
''//
''// Define the severity codes
''//
'
'
''//
''// MessageId: SCARD_F_INTERNAL_ERROR
''//
''// MessageText:
''//
''//  An internal consistency check failed
''//
'Public Const SCARD_F_INTERNAL_ERROR           As Long = &H80100001
'
''//
''// MessageId: SCARD_E_CANCELLED
''//
''// MessageText:
''//
''//  The action was cancelled by an SCardCancel request
''//
'Public Const SCARD_E_CANCELLED                As Long = &H80100002
'
''//
''// MessageId: SCARD_E_INVALID_HANDLE
''//
''// MessageText:
''//
''//  The supplied handle was invalid
''//
'Public Const SCARD_E_INVALID_HANDLE           As Long = &H80100003
'
''//
''// MessageId: SCARD_E_INVALID_PARAMETER
''//
''// MessageText:
''//
''//  One or more of the supplied parameters could not be properly interpreted
''//
'Public Const SCARD_E_INVALID_PARAMETER        As Long = &H80100004
'
''//
''// MessageId: SCARD_E_INVALID_TARGET
''//
''// MessageText:
''//
''//  Registry startup information is missing or invalid
''//
'Public Const SCARD_E_INVALID_TARGET           As Long = &H80100005
'
''//
''// MessageId: SCARD_E_NO_MEMORY
''//
''// MessageText:
''//
''//  Not enough memory available to complete this command
''//
'Public Const SCARD_E_NO_MEMORY                As Long = &H80100006
'
''//
''// MessageId: SCARD_F_WAITED_TOO_LONG
''//
''// MessageText:
''//
''//  An internal consistency timer has expired
''//
'Public Const SCARD_F_WAITED_TOO_LONG          As Long = &H80100007
'
''//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -