' ########################################################################################
' Microsoft Windows
' File: WinSCard.inc
' Contents: This header file provides the definitions and symbols necessary for an
' Application or Smart Card Service Provider to access the Smartcard Subsystem.
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_WinSCard_PBI)
#DEFINE PBX_WinSCard_PBI
%EQUATE `WINSCARD_INC = 1
#INCLUDE ONCE "Legacy/System/WTypes.inc"
#INCLUDE ONCE "Legacy/Platform/WinIoCtl.inc"
#INCLUDE ONCE "Legacy/Platform/WinSmCrd.inc"
#IF NOT %DEF(%SCARD_S_SUCCESS)
#INCLUDE ONCE "Legacy/System/SCardErr.inc"
#ENDIF
'/* In clr:pure we cannot mark data export with dllimport.
' * We should add small functions which returns the value of
' * the global.
' */
'#if !defined(_M_CEE_PURE)
'WINSCARDDATA extern const SCARD_IO_REQUEST
' g_rgSCardT0Pci,
' g_rgSCardT1Pci,
' g_rgSCardRawPci;
'#define SCARD_PCI_T0 (&g_rgSCardT0Pci)
'#define SCARD_PCI_T1 (&g_rgSCardT1Pci)
'#define SCARD_PCI_RAW (&g_rgSCardRawPci)
'#endif
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Service Manager Access Services
'//
'// The following services are used to manage user and terminal contexts for
'// Smart Cards.
'//
'typedef ULONG_PTR SCARDCONTEXT;
'typedef SCARDCONTEXT *PSCARDCONTEXT, *LPSCARDCONTEXT;
'typedef ULONG_PTR SCARDHANDLE;
'typedef SCARDHANDLE *PSCARDHANDLE, *LPSCARDHANDLE;
'#define SCARD_AUTOALLOCATE (DWORD)(-1)
%EQUATE `SCARD_AUTOALLOCATE = &HFFFFFFFF
'#define SCARD_SCOPE_USER 0 // The context is a user context, and any
' // database operations are performed within the
' // domain of the user.
'#define SCARD_SCOPE_TERMINAL 1 // 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.)
'#define SCARD_SCOPE_SYSTEM 2 // 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.)
%EQUATE `SCARD_SCOPE_USER = 0
%EQUATE `SCARD_SCOPE_TERMINAL = 1
%EQUATE `SCARD_SCOPE_SYSTEM = 2
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardEstablishContext LIB "WinSCard.dll" ALIAS "SCardEstablishContext" (BYVAL dwScope AS QUAD, pvReserved1 AS QUAD, pvReserved2 AS QUAD, phContext AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardEstablishContext LIB "winscard.dll" ALIAS "SCardEstablishContext" ( BYVAL dwScope AS QUAD , BYVAL pvReserved1 AS QUAD , BYVAL pvReserved2 AS QUAD , BYREF phContext AS QUAD ) AS LONG
#ENDIF
DECLARE FUNCTION SCardReleaseContext LIB "winscard.dll" ALIAS "SCardReleaseContext" ( BYVAL hContext AS QUAD ) AS LONG
DECLARE FUNCTION SCardIsValidContext LIB "winscard.dll" ALIAS "SCardIsValidContext" ( BYVAL hContext AS QUAD
 ) AS LONG
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Smart Card Database Management Services
'//
'// The following services provide for managing the Smart Card Database.
'//
'#define SCARD_ALL_READERS TEXT("SCard$AllReaders\000")
'#define SCARD_DEFAULT_READERS TEXT("SCard$DefaultReaders\000")
'#define SCARD_LOCAL_READERS TEXT("SCard$LocalReaders\000")
'#define SCARD_SYSTEM_READERS TEXT("SCard$SystemReaders\000")
$SCARD_ALL_READERS = "SCard$AllReaders" & $NUL & $NUL & $NUL
$SCARD_DEFAULT_READERS = "SCard$DefaultReaders" & $NUL & $NUL & $NUL
$SCARD_LOCAL_READERS = "SCard$LocalReaders" & $NUL & $NUL & $NUL
$SCARD_SYSTEM_READERS = "SCard$SystemReaders" & $NUL & $NUL & $NUL
%EQUATE `SCARD_PROVIDER_PRIMARY = 1 ' // Primary Provider Id
%EQUATE `SCARD_PROVIDER_CSP = 2 ' // Crypto Service Provider Id
%EQUATE `SCARD_PROVIDER_KSP = 3 ' // Key Storage Provider Id
'//
'// Database Reader routines
'//
DECLARE FUNCTION SCardListReaderGroupsA LIB "winscard.dll" ALIAS "SCardListReaderGroupsA" ( BYVAL hContext AS QUAD , BYREF mszGroups AS ASCIIZ , BYREF pcchGroups AS QUAD ) AS LONG
DECLARE FUNCTION SCardListReaderGroupsW LIB "winscard.dll" ALIAS "SCardListReaderGroupsW" ( BYVAL hContext AS QUAD
 , BYREF mszGroups AS WSTRINGZ
 , BYREF pcchGroups AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardListReaderGroups = SCardListReaderGroupsW
#ELSE
 MACRO SCardListReaderGroups = SCardListReaderGroupsA
#ENDIF
DECLARE FUNCTION SCardListReadersA LIB "winscard.dll" ALIAS "SCardListReadersA" ( BYVAL hContext AS QUAD , BYREF mszGroups AS ASCIIZ , BYREF mszReaders AS ASCIIZ , BYREF pcchReaders AS QUAD ) AS LONG
DECLARE FUNCTION SCardListReadersW LIB "winscard.dll" ALIAS "SCardListReadersW" ( BYVAL hContext AS QUAD
 , BYREF mszGroups AS WSTRINGZ
 , BYREF mszReaders AS WSTRINGZ
 , BYREF pcchReaders AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardListReaders = SCardListReadersW
#ELSE
 MACRO SCardListReaders = SCardListReadersA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardListCardsA LIB "WinSCard.dll" ALIAS "SCardListCardsA" (BYVAL hContext AS QUAD, BYVAL pbAtr AS BYTE PTR, BYVAL rgquidInterfaces AS GUID PTR, BYVAL cguidInterfaceCount AS QUAD, mszCards AS ASCIIZ, pcchCards AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardListCardsA LIB "winscard.dll" ALIAS "SCardListCardsA" ( BYVAL hContext AS QUAD , BYVAL pbAtr AS BYTE PTR , BYREF rgquidInterfaces AS GUID , BYVAL cguidInterfaceCount AS QUAD , BYREF mszCards AS ASCIIZ , BYREF pcchCards AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardListCardsW LIB "WinSCard.dll" ALIAS "SCardListCardsW" (BYVAL hContext AS QUAD, BYVAL pbAtr AS BYTE PTR, BYVAL rgquidInterfaces AS GUID PTR, BYVAL cguidInterfaceCount AS QUAD, mszCards AS WSTRINGZ, pcchCards AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardListCardsW LIB "winscard.dll" ALIAS "SCardListCardsW" ( BYVAL hContext AS QUAD , BYVAL pbAtr AS BYTE PTR , BYREF rgquidInterfaces AS GUID , BYVAL cguidInterfaceCount AS QUAD , BYREF mszCards AS WSTRINGZ , BYREF pcchCards AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardListCards = SCardListCardsW
#ELSE
 MACRO SCardListCards = SCardListCardsA
#ENDIF
'//
'// NOTE: The routine SCardListCards name differs from the PC/SC definition.
'// It should be:
'//
'// extern WINSCARDAPI LONG WINAPI
'// SCardListCardTypes(
'// IN SCARDCONTEXT hContext,
'// IN LPCBYTE pbAtr,
'// IN LPCGUID rgquidInterfaces,
'// IN DWORD cguidInterfaceCount,
'// OUT LPTSTR mszCards,
'// IN OUT LPDWORD pcchCards);
'//
'// Here's a work-around MACRO:
'#define SCardListCardTypes SCardListCards
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardListInterfacesA LIB "WinSCard.dll" ALIAS "SCardListInterfacesA" (BYVAL hContext AS QUAD, szCard AS ASCIIZ, BYVAL pguidInterfaces AS GUID PTR, pcguidInterfaces AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardListInterfacesA LIB "winscard.dll" ALIAS "SCardListInterfacesA" ( BYVAL hContext AS QUAD , BYREF szCard AS ASCIIZ , BYREF pguidInterfaces AS GUID , BYREF pcguidInterfaces AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardListInterfacesW LIB "WinSCard.dll" ALIAS "SCardListInterfacesW" (BYVAL hContext AS QUAD, szCard AS WSTRINGZ, BYVAL pguidInterfaces AS GUID PTR, pcguidInterfaces AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardListInterfacesW LIB "winscard.dll" ALIAS "SCardListInterfacesW" ( BYVAL hContext AS QUAD , BYREF szCard AS WSTRINGZ , BYREF pguidInterfaces AS GUID , BYREF pcguidInterfaces AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardListInterfaces = SCardListInterfacesW
#ELSE
 MACRO SCardListInterfaces = SCardListInterfacesA
#ENDIF
DECLARE FUNCTION SCardGetProviderIdA LIB "winscard.dll" ALIAS "SCardGetProviderIdA" ( BYVAL hContext AS QUAD , BYREF szCard AS ASCIIZ , BYREF pguidProviderId AS GUID ) AS LONG
DECLARE FUNCTION SCardGetProviderIdW LIB "winscard.dll" ALIAS "SCardGetProviderIdW" ( BYVAL hContext AS QUAD
 , BYREF szCard AS WSTRINGZ
 , BYREF pguidProviderId AS GUID
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardGetProviderId = SCardGetProviderIdW
#ELSE
 MACRO SCardGetProviderId = SCardGetProviderIdA
#ENDIF
'//
'// NOTE: The routine SCardGetProviderId in this implementation uses GUIDs.
'// The PC/SC definition uses BYTEs.
'//
DECLARE FUNCTION SCardGetCardTypeProviderNameA LIB "winscard.dll" ALIAS "SCardGetCardTypeProviderNameA" ( BYVAL hContext AS QUAD , BYREF szCardName AS ASCIIZ , BYVAL dwProviderId AS QUAD , BYREF szProvider AS ASCIIZ , BYREF pcchProvider AS QUAD ) AS LONG
DECLARE FUNCTION SCardGetCardTypeProviderNameW LIB "winscard.dll" ALIAS "SCardGetCardTypeProviderNameW" ( BYVAL hContext AS QUAD
 , BYREF szCardName AS WSTRINGZ
 , BYVAL dwProviderId AS DWORD
 , BYREF szProvider AS WSTRINGZ
 , BYREF pcchProvider AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardGetCardTypeProviderName = SCardGetCardTypeProviderNameW
#ELSE
 MACRO SCardGetCardTypeProviderName = SCardGetCardTypeProviderNameA
#ENDIF
'//
'// NOTE: This routine is an extension to the PC/SC definitions.
'//
'//
'// Database Writer routines
'//
DECLARE FUNCTION SCardIntroduceReaderGroupA LIB "winscard.dll" ALIAS "SCardIntroduceReaderGroupA" ( BYVAL hContext AS QUAD , BYREF szGroupName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardIntroduceReaderGroupW LIB "winscard.dll" ALIAS "SCardIntroduceReaderGroupW" ( BYVAL hContext AS QUAD
 , BYREF szGroupName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardIntroduceReaderGroup = SCardIntroduceReaderGroupW
#ELSE
 MACRO SCardIntroduceReaderGroup = SCardIntroduceReaderGroupA
#ENDIF
DECLARE FUNCTION SCardForgetReaderGroupA LIB "winscard.dll" ALIAS "SCardForgetReaderGroupA" ( BYVAL hContext AS QUAD , BYREF szGroupName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardForgetReaderGroupW LIB "winscard.dll" ALIAS "SCardForgetReaderGroupW" ( BYVAL hContext AS QUAD
 , BYREF szGroupName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardForgetReaderGroup = SCardForgetReaderGroupW
#ELSE
 MACRO SCardForgetReaderGroup = SCardForgetReaderGroupA
#ENDIF
DECLARE FUNCTION SCardIntroduceReaderA LIB "winscard.dll" ALIAS "SCardIntroduceReaderA" ( BYVAL hContext AS QUAD , BYREF szReaderName AS ASCIIZ , BYREF szDeviceName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardIntroduceReaderW LIB "winscard.dll" ALIAS "SCardIntroduceReaderW" ( BYVAL hContext AS QUAD
 , BYREF szReaderName AS WSTRINGZ
 , BYREF szDeviceName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardIntroduceReader = SCardIntroduceReaderW
#ELSE
 MACRO SCardIntroduceReader = SCardIntroduceReaderA
#ENDIF
DECLARE FUNCTION SCardForgetReaderA LIB "winscard.dll" ALIAS "SCardForgetReaderA" ( BYVAL hContext AS QUAD , BYREF szReaderName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardForgetReaderW LIB "winscard.dll" ALIAS "SCardForgetReaderW" ( BYVAL hContext AS QUAD
 , BYREF szReaderName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardForgetReader = SCardForgetReaderW
#ELSE
 MACRO SCardForgetReader = SCardForgetReaderA
#ENDIF
DECLARE FUNCTION SCardAddReaderToGroupA LIB "winscard.dll" ALIAS "SCardAddReaderToGroupA" ( BYVAL hContext AS QUAD , BYREF szReaderName AS ASCIIZ , BYREF szGroupName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardAddReaderToGroupW LIB "winscard.dll" ALIAS "SCardAddReaderToGroupW" ( BYVAL hContext AS QUAD
 , BYREF szReaderName AS WSTRINGZ
 , BYREF szGroupName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardAddReaderToGroup = SCardAddReaderToGroupW
#ELSE
 MACRO SCardAddReaderToGroup = SCardAddReaderToGroupA
#ENDIF
DECLARE FUNCTION SCardRemoveReaderFromGroupA LIB "winscard.dll" ALIAS "SCardRemoveReaderFromGroupA" ( BYVAL hContext AS QUAD , BYREF szReaderName AS ASCIIZ , BYREF szGroupName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardRemoveReaderFromGroupW LIB "winscard.dll" ALIAS "SCardRemoveReaderFromGroupW" ( BYVAL hContext AS QUAD
 , BYREF szReaderName AS WSTRINGZ
 , BYREF szGroupName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardRemoveReaderFromGroup = SCardRemoveReaderFromGroupW
#ELSE
 MACRO SCardRemoveReaderFromGroup = SCardRemoveReaderFromGroupA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardIntroduceCardTypeA LIB "WinSCard.dll" ALIAS "SCardIntroduceCardTypeA" (BYVAL hContext AS QUAD, szCardName AS ASCIIZ, pguidPrimaryProvider AS GUID, BYVAL rgGuidInterfaces AS GUID PTR, BYVAL dwInterfaceCount AS QUAD, BYVAL pbAtr AS BYTE PTR, BYVAL pbAtrMask AS BYTE PTR, BYVAL cbAtrLen AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardIntroduceCardTypeA LIB "winscard.dll" ALIAS "SCardIntroduceCardTypeA" ( BYVAL hContext AS QUAD , BYREF szCardName AS ASCIIZ , BYREF pguidPrimaryProvider AS GUID , BYREF rgguidInterfaces AS GUID , BYVAL dwInterfaceCount AS QUAD , BYVAL pbAtr AS BYTE PTR , BYVAL pbAtrMask AS BYTE PTR , BYVAL cbAtrLen AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardIntroduceCardTypeW LIB "WinSCard.dll" ALIAS "SCardIntroduceCardTypeW" (BYVAL hContext AS QUAD, szCardName AS WSTRINGZ, pguidPrimaryProvider AS GUID, BYVAL rgGuidInterfaces AS GUID PTR, BYVAL dwInterfaceCount AS QUAD, BYVAL pbAtr AS BYTE PTR, BYVAL pbAtrMask AS BYTE PTR, BYVAL cbAtrLen AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardIntroduceCardTypeW LIB "winscard.dll" ALIAS "SCardIntroduceCardTypeW" ( BYVAL hContext AS QUAD , BYREF szCardName AS WSTRINGZ , BYREF pguidPrimaryProvider AS GUID , BYREF rgguidInterfaces AS GUID , BYVAL dwInterfaceCount AS QUAD , BYVAL pbAtr AS BYTE PTR , BYVAL pbAtrMask AS BYTE PTR , BYVAL cbAtrLen AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardIntroduceCardType = SCardIntroduceCardTypeW
#ELSE
 MACRO SCardIntroduceCardType = SCardIntroduceCardTypeA
#ENDIF
'//
'// NOTE: The routine SCardIntroduceCardType's parameters' order differs from
'// the PC/SC definition. It should be:
'//
'// extern WINSCARDAPI LONG WINAPI
'// SCardIntroduceCardType(
'// IN SCARDCONTEXT hContext,
'// IN LPCTSTR szCardName,
'// IN LPCBYTE pbAtr,
'// IN LPCBYTE pbAtrMask,
'// IN DWORD cbAtrLen,
'// IN LPCGUID pguidPrimaryProvider,
'// IN LPCGUID rgguidInterfaces,
'// IN DWORD dwInterfaceCount);
'//
'// Here's a work-around MACRO:
'#define PCSCardIntroduceCardType(hContext, szCardName, pbAtr, pbAtrMask, cbAtrLen, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount) \
' SCardIntroduceCardType(hContext, szCardName, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen)
DECLARE FUNCTION SCardSetCardTypeProviderNameA LIB "winscard.dll" ALIAS "SCardSetCardTypeProviderNameA" ( BYVAL hContext AS QUAD , BYREF szCardName AS ASCIIZ , BYVAL dwProviderId AS QUAD , BYREF szProvider AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardSetCardTypeProviderNameW LIB "winscard.dll" ALIAS "SCardSetCardTypeProviderNameW" ( BYVAL hContext AS QUAD
 , BYREF szCardName AS WSTRINGZ
 , BYVAL dwProviderId AS DWORD
 , BYREF szProvider AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardSetCardTypeProviderName = SCardSetCardTypeProviderNameW
#ELSE
 MACRO SCardSetCardTypeProviderName = SCardSetCardTypeProviderNameA
#ENDIF
'//
'// NOTE: This routine is an extention to the PC/SC specifications.
'//
DECLARE FUNCTION SCardForgetCardTypeA LIB "winscard.dll" ALIAS "SCardForgetCardTypeA" ( BYVAL hContext AS QUAD , BYREF szCardName AS ASCIIZ ) AS LONG
DECLARE FUNCTION SCardForgetCardTypeW LIB "winscard.dll" ALIAS "SCardForgetCardTypeW" ( BYVAL hContext AS QUAD
 , BYREF szCardName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardForgetCardType = SCardForgetCardTypeW
#ELSE
 MACRO SCardForgetCardType = SCardForgetCardTypeA
#ENDIF
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Service Manager Support Routines
'//
'// The following services are supplied to simplify the use of the Service
'// Manager API.
'//
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardFreeMemory LIB "WinSCard.dll" ALIAS "SCardFreeMemory" (BYVAL hContext AS QUAD, pvMem AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardFreeMemory LIB "winscard.dll" ALIAS "SCardFreeMemory" ( BYVAL hContext AS QUAD , BYVAL pvMem AS QUAD ) AS LONG
#ENDIF
DECLARE FUNCTION SCardAccessStartedEvent LIB "winscard.dll" ALIAS "SCardAccessStartedEvent" ( ) AS QUAD
DECLARE SUB SCardReleaseStartedEvent LIB "winscard.dll" ALIAS "SCardReleaseStartedEvent" () ' void
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Reader Services
'//
'// The following services supply means for tracking cards within readers.
'//
' // Size = 56 bytes
TYPE SCARD_READERSTATEA DWORD
 szReader AS ASCIIZ PTR
 pvUserData AS DWORD
 dwCurrentState AS DWORD
 dwEventState AS DWORD
 cbAtr AS DWORD
 rgbAtr(35) AS BYTE ' BYTE rgbAtr[36]
END TYPE
' // Size = 56 bytes
TYPE SCARD_READERSTATEW DWORD
 szReader AS WSTRINGZ PTR
 pvUserData AS DWORD
 dwCurrentState AS DWORD
 dwEventState AS DWORD
 cbAtr AS DWORD
 rgbAtr(35) AS BYTE ' BYTE rgbAtr[36]
END TYPE
#IF %DEF(%UNICODE)
 MACRO SCARD_READERSTATE = SCARD_READERSTATEW
#ELSE
 MACRO SCARD_READERSTATE = SCARD_READERSTATEA
#ENDIF
'#define SCARD_STATE_UNAWARE 0x00000000 // 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.
'#define SCARD_STATE_IGNORE 0x00000001 // The application requested that
' // this reader be ignored. No other
' // bits will be set.
'#define SCARD_STATE_CHANGED 0x00000002 // 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.
'#define SCARD_STATE_UNKNOWN 0x00000004 // 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.
'#define SCARD_STATE_UNAVAILABLE 0x00000008 // This implies that the actual
' // state of this reader is not
' // available. If this bit is set,
' // then all the following bits are
' // clear.
'#define SCARD_STATE_EMPTY 0x00000010 // This implies that there is not
' // card in the reader. If this bit
' // is set, all the following bits
' // will be clear.
'#define SCARD_STATE_PRESENT 0x00000020 // This implies that there is a card
' // in the reader.
'#define SCARD_STATE_ATRMATCH 0x00000040 // 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.
'#define SCARD_STATE_EXCLUSIVE 0x00000080 // 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.
'#define SCARD_STATE_INUSE 0x00000100 // 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.
'#define SCARD_STATE_MUTE 0x00000200 // This implies that the card in the
' // reader is unresponsive or not
' // supported by the reader or
' // software.
'#define SCARD_STATE_UNPOWERED 0x00000400 // This implies that the card in the
' // reader has not been powered up.
%EQUATE `SCARD_STATE_UNAWARE = &H00000000
%EQUATE `SCARD_STATE_IGNORE = &H00000001
%EQUATE `SCARD_STATE_CHANGED = &H00000002
%EQUATE `SCARD_STATE_UNKNOWN = &H00000004
%EQUATE `SCARD_STATE_UNAVAILABLE = &H00000008
%EQUATE `SCARD_STATE_EMPTY = &H00000010
%EQUATE `SCARD_STATE_PRESENT = &H00000020
%EQUATE `SCARD_STATE_ATRMATCH = &H00000040
%EQUATE `SCARD_STATE_EXCLUSIVE = &H00000080
%EQUATE `SCARD_STATE_INUSE = &H00000100
%EQUATE `SCARD_STATE_MUTE = &H00000200
%EQUATE `SCARD_STATE_UNPOWERED = &H00000400
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardLocateCardsA LIB "WinSCard.dll" ALIAS "SCardLocateCardsA" (BYVAL hContext AS QUAD, mszCards AS ASCIIZ, BYVAL rgReaderStates AS SCARD_READERSTATEA PTR, BYVAL cReaders AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardLocateCardsA LIB "winscard.dll" ALIAS "SCardLocateCardsA" ( BYVAL hContext AS QUAD , BYREF mszCards AS ASCIIZ , BYREF rgReaderStates AS SCARD_READERSTATEA , BYVAL cReaders AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardLocateCardsW LIB "WinSCard.dll" ALIAS "SCardLocateCardsW" (BYVAL hContext AS QUAD, mszCards AS WSTRINGZ, BYVAL rgReaderStates AS SCARD_READERSTATEW PTR, BYVAL cReaders AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardLocateCardsW LIB "winscard.dll" ALIAS "SCardLocateCardsW" ( BYVAL hContext AS QUAD , BYREF mszCards AS ASCIIZ , BYREF rgReaderStates AS SCARD_READERSTATEW , BYVAL cReaders AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardLocateCards = SCardLocateCardsW
#ELSE
 MACRO SCardLocateCards = SCardLocateCardsA
#ENDIF
'#if (NTDDI_VERSION >= NTDDI_WINXP)
' // Size = 76 bytes
TYPE SCARD_ATRMASK DWORD
 cbAtr AS DWORD ' DWORD // Number of bytes in the ATR and the mask.
 rgbAtr(35) AS BYTE ' BYTE rgbAtr[36] // Atr of card (extra alignment bytes)
 rgbMask(35) AS BYTE ' BYTE rgbMask[36] // Mask for the Atr (extra alignment bytes)
END TYPE
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardLocateCardsByATRA LIB "WinSCard.dll" ALIAS "SCardLocateCardsByATRA" (BYVAL hContext AS QUAD, BYVAL rgAtrMasks AS SCARD_ATRMASK PTR, BYVAL cAtrs AS QUAD, BYVAL rgReaderStates AS SCARD_READERSTATEA PTR, BYVAL cReaders AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardLocateCardsByATRA LIB "winscard.dll" ALIAS "SCardLocateCardsByATRA" ( BYVAL hContext AS QUAD , BYREF rgAtrMasks AS SCARD_ATRMASK , BYVAL cAtrs AS QUAD , BYREF rgReaderStates AS SCARD_READERSTATEA , BYVAL cReaders AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardLocateCardsByATRW LIB "WinSCard.dll" ALIAS "SCardLocateCardsByATRW" (BYVAL hContext AS QUAD, BYVAL rgAtrMasks AS SCARD_ATRMASK PTR, BYVAL cAtrs AS QUAD, BYVAL rgReaderStates AS SCARD_READERSTATEW PTR, BYVAL cReaders AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardLocateCardsByATRW LIB "winscard.dll" ALIAS "SCardLocateCardsByATRW" ( BYVAL hContext AS QUAD , BYREF rgAtrMasks AS SCARD_ATRMASK , BYVAL cAtrs AS QUAD , BYREF rgReaderStates AS SCARD_READERSTATEW , BYVAL cReaders AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardLocateCardsByATR = SCardLocateCardsByATRW
#ELSE
 MACRO SCardLocateCardsByATR = SCardLocateCardsByATRA
#ENDIF
'#endif // (NTDDI_VERSION >= NTDDI_WINXP)
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardGetStatusChangeA LIB "WinSCard.dll" ALIAS "SCardGetStatusChangeA" (BYVAL hContext AS QUAD, BYVAL dwTimeout AS QUAD, BYVAL rgReaderStates AS SCARD_READERSTATEA PTR, BYVAL cReaders AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardGetStatusChangeA LIB "winscard.dll" ALIAS "SCardGetStatusChangeA" ( BYVAL hContext AS QUAD , BYVAL dwTimeout AS QUAD , BYREF rgReaderStates AS SCARD_READERSTATEA , BYVAL cReaders AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardGetStatusChangeW LIB "WinSCard.dll" ALIAS "SCardGetStatusChangeW" (BYVAL hContext AS QUAD, BYVAL dwTimeout AS QUAD, BYVAL rgReaderStates AS SCARD_READERSTATEW PTR, BYVAL cReaders AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardGetStatusChangeW LIB "winscard.dll" ALIAS "SCardGetStatusChangeW" ( BYVAL hContext AS QUAD , BYVAL dwTimeout AS QUAD , BYREF rgReaderStates AS SCARD_READERSTATEW , BYVAL cReaders AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardGetStatusChange = SCardGetStatusChangeW
#ELSE
 MACRO SCardGetStatusChange = SCardGetStatusChangeA
#ENDIF
DECLARE FUNCTION SCardCancel LIB "winscard.dll" ALIAS "SCardCancel" ( BYVAL hContext AS QUAD ) AS LONG
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Card/Reader Communication Services
'//
'// The following services provide means for communication with the card.
'//
%EQUATE `SCARD_SHARE_EXCLUSIVE = 1 ' // This application is not willing to share this
 ' // card with other applications.
%EQUATE `SCARD_SHARE_SHARED = 2 ' // This application is willing to share this
 ' // card with other applications.
%EQUATE `SCARD_SHARE_DIRECT = 3 ' // This application demands direct control of
 ' // the reader, so it is not available to other
 ' // applications.
%EQUATE `SCARD_LEAVE_CARD = 0 ' // Don't do anything special on close
%EQUATE `SCARD_RESET_CARD = 1 ' // Reset the card on close
%EQUATE `SCARD_UNPOWER_CARD = 2 ' // Power down the card on close
%EQUATE `SCARD_EJECT_CARD = 3 ' // Eject the card on close
DECLARE FUNCTION SCardConnectA LIB "winscard.dll" ALIAS "SCardConnectA" ( BYVAL hContext AS QUAD , BYREF szReader AS ASCIIZ , BYVAL dwShareMode AS QUAD , BYVAL dwPreferredProtocols AS QUAD , BYREF phCard AS QUAD , BYREF pdwActiveProtocol AS QUAD ) AS LONG
DECLARE FUNCTION SCardConnectW LIB "winscard.dll" ALIAS "SCardConnectW" ( BYVAL hContext AS QUAD
 , BYREF szReader AS WSTRINGZ
 , BYVAL dwShareMode AS DWORD
 , BYVAL dwPreferredProtocols AS DWORD
 , BYREF phCard AS DWORD
 , BYREF pdwActiveProtocol AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardConnect = SCardConnectW
#ELSE
 MACRO SCardConnect = SCardConnectA
#ENDIF
DECLARE FUNCTION SCardReconnect LIB "winscard.dll" ALIAS "SCardReconnect" ( BYVAL hCard AS QUAD , BYVAL dwShareMode AS QUAD , BYVAL dwPreferredProtocols AS QUAD , BYVAL dwInitialization AS QUAD , BYREF pdwActiveProtocol AS QUAD ) AS LONG
DECLARE FUNCTION SCardDisconnect LIB "winscard.dll" ALIAS "SCardDisconnect" ( BYVAL hCard AS QUAD
 , BYVAL dwDisposition AS DWORD
 ) AS LONG
DECLARE FUNCTION SCardBeginTransaction LIB "winscard.dll" ALIAS "SCardBeginTransaction" ( BYVAL hCard AS DWORD
 ) AS LONG
DECLARE FUNCTION SCardEndTransaction LIB "winscard.dll" ALIAS "SCardEndTransaction" ( BYVAL hCard AS DWORD
 , BYVAL dwDisposition AS DWORD
 ) AS LONG
DECLARE FUNCTION SCardCancelTransaction LIB "winscard.dll" ALIAS "SCardCancelTransaction" ( BYVAL hCard AS DWORD
 ) AS LONG
'//
'// NOTE: This call corresponds to the PC/SC SCARDCOMM::Cancel routine,
'// terminating a blocked SCardBeginTransaction service.
'//
DECLARE FUNCTION SCardState LIB "winscard.dll" ALIAS "SCardState" ( BYVAL hCard AS QUAD , BYREF pdwState AS QUAD , BYREF pdwProtocol AS QUAD , BYVAL pbAtr AS BYTE PTR , BYREF pcbAtrLen AS QUAD ) AS LONG
'//
'// NOTE: SCardState is an obsolete routine. PC/SC has replaced it with
'// SCardStatus.
'//
DECLARE FUNCTION SCardStatusA LIB "winscard.dll" ALIAS "SCardStatusA" ( BYVAL hCard AS QUAD , BYREF szReaderName AS ASCIIZ , BYREF pcchReaderLen AS QUAD , BYREF pdwState AS QUAD , BYREF pdwProtocol AS QUAD , BYVAL pbAtr AS BYTE PTR , BYREF pcbAtrLen AS QUAD ) AS LONG
DECLARE FUNCTION SCardStatusW LIB "winscard.dll" ALIAS "SCardStatusW" ( BYVAL hCard AS QUAD
 , BYREF szReaderName AS WSTRINGZ
 , BYREF pcchReaderLen AS DWORD
 , BYREF pdwState AS DWORD
 , BYREF pdwProtocol AS DWORD
 , BYVAL pbAtr AS BYTE PTR
 , BYREF pcbAtrLen AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardStatus = SCardStatusW
#ELSE
 MACRO SCardStatus = SCardStatusA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardTransmit LIB "WinSCard.dll" ALIAS "SCardTransmit" (BYVAL hCard AS QUAD, pioSendPci AS QUAD, BYVAL pbSendBuffer AS BYTE PTR, BYVAL cbSendLength AS QUAD, pioRecvPci AS QUAD, BYVAL pbRecvBuffer AS BYTE PTR, pcbRecvLength AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardTransmit LIB "winscard.dll" ALIAS "SCardTransmit" ( BYVAL hCard AS QUAD , BYREF pioSendPci AS SCARD_IO_REQUEST , BYVAL pbSendBuffer AS BYTE PTR , BYVAL cbSendLength AS QUAD , BYREF pioRecvPci AS SCARD_IO_REQUEST , BYVAL pbRecvBuffer AS BYTE PTR , BYREF pcbRecvLength AS QUAD ) AS LONG
#ENDIF
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Reader Control Routines
'//
'// The following services provide for direct, low-level manipulation of the
'// reader by the calling application allowing it control over the
'// attributes of the communications with the card.
'//
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardControl LIB "WinSCard.dll" ALIAS "SCardControl" (BYVAL hCard AS QUAD, BYVAL dwControlCode AS QUAD, lpInBuffer AS ANY, BYVAL nInBufferSize AS QUAD, lpOutBuffer AS ANY, BYVAL nOutBufferSize AS QUAD, lpBytesReturned AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardControl LIB "winscard.dll" ALIAS "SCardControl" ( BYVAL hCard AS QUAD , BYVAL dwControlCode AS QUAD , BYVAL lpInBuffer AS QUAD , BYVAL nInBufferSize AS QUAD , BYREF lpOutBuffer AS ANY , BYVAL nOutBufferSize AS QUAD , BYREF lpBytesReturned AS QUAD ) AS LONG
#ENDIF
DECLARE FUNCTION SCardGetAttrib LIB "winscard.dll" ALIAS "SCardGetAttrib" ( BYVAL hCard AS QUAD , BYVAL dwAttrId AS QUAD , BYVAL pbAttr AS QUAD , BYREF pcbAttrLen AS QUAD ) AS LONG
'//
'// NOTE: The routine SCardGetAttrib's name differs from the PC/SC definition.
'// It should be:
'//
'// extern WINSCARDAPI LONG WINAPI
'// SCardGetReaderCapabilities(
'// IN SCARDHANDLE hCard,
'// IN DWORD dwTag,
'// OUT LPBYTE pbAttr,
'// IN OUT LPDWORD pcbAttrLen);
'//
'// Here's a work-around MACRO:
'#define SCardGetReaderCapabilities SCardGetAttrib
DECLARE FUNCTION SCardSetAttrib LIB "winscard.dll" ALIAS "SCardSetAttrib" ( BYVAL hCard AS QUAD , BYVAL dwAttrId AS QUAD , BYVAL pbAttr AS BYTE PTR , BYVAL cbAttrLen AS QUAD ) AS LONG
'//
'// NOTE: The routine SCardSetAttrib's name differs from the PC/SC definition.
'// It should be:
'//
'// extern WINSCARDAPI LONG WINAPI
'// SCardSetReaderCapabilities(
'// IN SCARDHANDLE hCard,
'// IN DWORD dwTag,
'// OUT LPBYTE pbAttr,
'// IN OUT LPDWORD pcbAttrLen);
'//
'// Here's a work-around MACRO:
'#define SCardSetReaderCapabilities SCardSetAttrib
'//
'////////////////////////////////////////////////////////////////////////////////
'//
'// Smart Card Dialog definitions
'//
'// The following section contains structures and exported function
'// declarations for the Smart Card Common Dialog dialog.
'//
'// Defined constants
'// Flags
%EQUATE `SC_DLG_MINIMAL_UI = &H01
%EQUATE `SC_DLG_NO_UI = &H02
%EQUATE `SC_DLG_FORCE_UI = &H04
%EQUATE `SCERR_NOCARDNAME = &H4000
%EQUATE `SCERR_NOGUIDS = &H8000
'typedef SCARDHANDLE (WINAPI *LPOCNCONNPROCA) (IN SCARDCONTEXT, IN LPSTR, IN LPSTR, IN PVOID);
'FUNCTION OCNCONNPROCA ( ' BYVAL DWORD,
' BYREF ASCIIZ,
' BYREF ASCIIZ,
' BYVAL DWORD
' ) AS DWORD ' SCANHANDLE
'typedef SCARDHANDLE (WINAPI *LPOCNCONNPROCW) (IN SCARDCONTEXT, IN LPWSTR, IN LPWSTR, IN PVOID);
'FUNCTION OCNCONNPROCW ( ' BYVAL DWORD,
' BYREF WSTRINGZ,
' BYREF WSTRINGZ,
' BYVAL DWORD
' ) AS DWORD ' SCANHANDLE
'typedef BOOL (WINAPI *LPOCNCHKPROC) (IN SCARDCONTEXT, IN SCARDHANDLE, IN PVOID);
'FUNCTION OCNCHKPROC ( ' BYVAL DWORD,
' BYVAL DWORD,
' BYVAL DWORD
' ) AS LONG
'typedef void (WINAPI *LPOCNDSCPROC) (IN SCARDCONTEXT, IN SCARDHANDLE, IN PVOID);
'SUB OCNDSCPROC ( ' BYVAL DWORD,
' BYVAL DWORD
' BYVAL DWORD
' )
'//
'// OPENCARD_SEARCH_CRITERIA: In order to specify a user-extended search,
'// lpfnCheck must not be NULL. Moreover, the connection to be made to the
'// card before performing the callback must be indicated by either providing
'// lpfnConnect and lpfnDisconnect OR by setting dwShareMode.
'// If both the connection callbacks and dwShareMode are non-NULL, the callbacks
'// will be used.
'//
' // Size = 52 bytes
TYPE OPENCARD_SEARCH_CRITERIAA DWORD
 dwStructSize AS DWORD
 lpstrGroupNames AS ASCIIZ PTR
 nMaxGroupNames AS DWORD
 rgguidInterfaces AS GUID PTR
 cguidInterfaces AS DWORD
 lpstrCardNames AS ASCIIZ PTR
 nMaxCardNames AS DWORD
 lpfnCheck AS DWORD
 lpfnConnect AS DWORD
 lpfnDisconnect AS DWORD
 pvUserData AS DWORD
 dwShareMode AS DWORD
 dwPreferredProtocols AS DWORD
END TYPE
' // Size = 52 bytes
TYPE OPENCARD_SEARCH_CRITERIAW DWORD
 dwStructSize AS DWORD
 lpstrGroupNames AS WSTRINGZ PTR
 nMaxGroupNames AS DWORD
 rgguidInterfaces AS GUID PTR
 cguidInterfaces AS DWORD
 lpstrCardNames AS WSTRINGZ PTR
 nMaxCardNames AS DWORD
 lpfnCheck AS DWORD
 lpfnConnect AS DWORD
 lpfnDisconnect AS DWORD
 pvUserData AS DWORD
 dwShareMode AS DWORD
 dwPreferredProtocols AS DWORD
END TYPE
#IF %DEF(%UNICODE)
 MACRO OPENCARD_SEARCH_CRITERIA = OPENCARD_SEARCH_CRITERIAW
#ELSE
 MACRO OPENCARD_SEARCH_CRITERIA = OPENCARD_SEARCH_CRITERIAA
#ENDIF
'//
'// OPENCARDNAME_EX: used by SCardUIDlgSelectCard; replaces obsolete OPENCARDNAME
'//
' // Size = 72 bytes
TYPE OPENCARDNAME_EXA DWORD
 dwStructSize AS DWORD
 hSCardContext AS DWORD ' SCARDCONTEXT
 hwndOwner AS DWORD
 dwFlags AS DWORD
 lpstrTitle AS ASCIIZ PTR
 lpstrSearchDesc AS ASCIIZ PTR
 hIcon AS DWORD ' HICON
 pOpenCardSearchCriteria AS OPENCARD_SEARCH_CRITERIA PTR ' POPENCARD_SEARCH_CRITERIAA
 lpfnConnect AS DWORD
 pvUserData AS DWORD
 dwShareMode AS DWORD
 dwPreferredProtocols AS DWORD
 lpstrRdr AS ASCIIZ PTR
 nMaxRdr AS DWORD
 lpstrCard AS ASCIIZ PTR
 nMaxCard AS DWORD
 dwActiveProtocol AS DWORD
 hCardHandle AS DWORD ' SCARDHANDLE
END TYPE
' // Size = 72 bytes
TYPE OPENCARDNAME_EXW DWORD
 dwStructSize AS DWORD
 hSCardContext AS DWORD ' SCARDCONTEXT
 hwndOwner AS DWORD
 dwFlags AS DWORD
 lpstrTitle AS WSTRINGZ PTR
 lpstrSearchDesc AS WSTRINGZ PTR
 hIcon AS DWORD ' HICON
 pOpenCardSearchCriteria AS OPENCARD_SEARCH_CRITERIAW PTR ' POPENCARD_SEARCH_CRITERIAW
 lpfnConnect AS DWORD
 pvUserData AS DWORD
 dwShareMode AS DWORD
 dwPreferredProtocols AS DWORD
 lpstrRdr AS WSTRINGZ PTR
 nMaxRdr AS DWORD
 lpstrCard AS WSTRINGZ PTR
 nMaxCard AS DWORD
 dwActiveProtocol AS DWORD
 hCardHandle AS DWORD ' SCARDHANDLE
END TYPE
#IF %DEF(%UNICODE)
 MACRO OPENCARDNAME_EX = OPENCARDNAME_EXW
#ELSE
 MACRO OPENCARDNAME_EX = OPENCARDNAME_EXA
#ENDIF
'//
'// SCardUIDlgSelectCard replaces GetOpenCardName
'//
DECLARE FUNCTION SCardUIDlgSelectCardA LIB "winscard.dll" ALIAS "SCardUIDlgSelectCardA" ( BYREF pDlgStruc AS OPENCARDNAME_EXA ) AS LONG
DECLARE FUNCTION SCardUIDlgSelectCardW LIB "winscard.dll" ALIAS "SCardUIDlgSelectCardW" ( BYREF pDlgStruc AS OPENCARDNAME_EXW
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardUIDlgSelectCard = SCardUIDlgSelectCardW
#ELSE
 MACRO SCardUIDlgSelectCard = SCardUIDlgSelectCardA
#ENDIF
'//
'// "Smart Card Common Dialog" definitions for backwards compatibility
'// with the Smart Card Base Services SDK version 1.0
'//
' // Size = 92 bytes
TYPE OPENCARDNAMEA DWORD
 dwStructSize AS DWORD
 hwndOwner AS DWORD
 hSCardContext AS DWORD ' SCARDCONTEXT
 lpstrGroupNames AS ASCIIZ PTR
 nMaxGroupNames AS DWORD
 lpstrCardNames AS ASCIIZ PTR
 nMaxCardNames AS DWORD
 rgguidInterfaces AS GUID PTR
 cguidInterfaces AS DWORD
 lpstrRdr AS ASCIIZ PTR
 nMaxRdr AS DWORD
 lpstrCard AS ASCIIZ PTR
 nMaxCard AS DWORD
 lpstrTitle AS ASCIIZ PTR
 dwFlags AS DWORD
 pvUserData AS DWORD
 dwShareMode AS DWORD
 dwPreferredProtocols AS DWORD
 dwActiveProtocol AS DWORD
 lpfnConnect AS DWORD
 lpfnCheck AS DWORD
 lpfnDisconnect AS DWORD
 hCardHandle AS DWORD ' SCARDHANDLE
END TYPE
' // Size = 92 bytes
TYPE OPENCARDNAMEW DWORD
 dwStructSize AS DWORD
 hwndOwner AS DWORD
 hSCardContext AS DWORD ' SCARDCONTEXT
 lpstrGroupNames AS WSTRINGZ PTR
 nMaxGroupNames AS DWORD
 lpstrCardNames AS WSTRINGZ PTR
 nMaxCardNames AS DWORD
 rgguidInterfaces AS GUID PTR
 cguidInterfaces AS DWORD
 lpstrRdr AS WSTRINGZ PTR
 nMaxRdr AS DWORD
 lpstrCard AS WSTRINGZ PTR
 nMaxCard AS DWORD
 lpstrTitle AS WSTRINGZ PTR
 dwFlags AS DWORD
 pvUserData AS DWORD
 dwShareMode AS DWORD
 dwPreferredProtocols AS DWORD
 dwActiveProtocol AS DWORD
 lpfnConnect AS DWORD
 lpfnCheck AS DWORD
 lpfnDisconnect AS DWORD
 hCardHandle AS DWORD ' SCARDHANDLE
END TYPE
#IF %DEF(%UNICODE)
 MACRO OPENCARDNAME = OPENCARDNAMEW
#ELSE
 MACRO OPENCARDNAME = OPENCARDNAMEA
#ENDIF
DECLARE FUNCTION GetOpenCardNameA LIB "winscard.dll" ALIAS "GetOpenCardNameA" ( BYREF pDlgStruc AS OPENCARDNAMEA ) AS LONG
DECLARE FUNCTION GetOpenCardNameW LIB "winscard.dll" ALIAS "GetOpenCardNameW" ( BYREF pDlgStruc AS OPENCARDNAMEW
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO GetOpenCardName = GetOpenCardNameW
#ELSE
 MACRO GetOpenCardName = GetOpenCardNameA
#ENDIF
DECLARE FUNCTION SCardDlgExtendedError LIB "winscard.dll" ALIAS "SCardDlgExtendedError" ( ) AS LONG
'#if (NTDDI_VERSION >= NTDDI_VISTA)
'//
'// Smartcard Caching API
'//
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardReadCacheA LIB "WinSCard.dll" ALIAS "SCardReadCacheA" (BYVAL hContext AS QUAD, CardIdentifier AS GUID, BYVAL FreshnessCounter AS QUAD, LookupName AS ASCIIZ, BYVAL pData AS BYTE PTR, DataLen AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardReadCacheA LIB "winscard.dll" ALIAS "SCardReadCacheA" ( BYVAL hContext AS QUAD , BYREF CardIdentifier AS GUID , BYVAL FreshnessCounter AS QUAD , BYREF LookupName AS ASCIIZ , BYREF Data AS ANY , BYREF DataLen AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SCardReadCacheW LIB "WinSCard.dll" ALIAS "SCardReadCacheW" (BYVAL hContext AS QUAD, CardIdentifier AS GUID, BYVAL FreshnessCounter AS QUAD, LookupName AS WSTRINGZ, BYVAL pData AS BYTE PTR, DataLen AS QUAD) AS LONG
#ELSE
DECLARE FUNCTION SCardReadCacheW LIB "winscard.dll" ALIAS "SCardReadCacheW" ( BYVAL hContext AS QUAD , BYREF CardIdentifier AS GUID , BYVAL FreshnessCounter AS QUAD , BYREF LookupName AS WSTRINGZ , BYREF Data AS ANY , BYREF DataLen AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO SCardReadCache = SCardReadCacheW
#ELSE
 MACRO SCardReadCache = SCardReadCacheA
#ENDIF
DECLARE FUNCTION SCardWriteCacheA LIB "winscard.dll" ALIAS "SCardWriteCacheA" ( BYVAL hContext AS QUAD , BYREF CardIdentifier AS GUID , BYVAL FreshnessCounter AS QUAD , BYREF LookupName AS ASCIIZ , BYVAL Data AS BYTE PTR , BYVAL DataLen AS QUAD ) AS LONG
DECLARE FUNCTION SCardWriteCacheW LIB "winscard.dll" ALIAS "SCardWriteCacheW" ( BYVAL hContext AS QUAD
 , BYREF CardIdentifier AS GUID
 , BYVAL FreshnessCounter AS DWORD
 , BYREF LookupName AS WSTRINGZ
 , BYVAL Data AS BYTE PTR
 , BYVAL DataLen AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO SCardWriteCache = SCardWriteCacheW
#ELSE
 MACRO SCardWriteCache = SCardWriteCacheA
#ENDIF
'#endif // (NTDDI_VERSION >= NTDDI_VISTA)
#ENDIF
