SCard Delphi DLL Reference Documentation

SCard

Current Version: 9.5.0.88

A wrapper around the Resource Manager API of the PC/SC architecture for smart cards. On Windows it is a wrapper around the WinSCard functions implemented in the winscard.dll. On other systems (such as Linux) it is a wrapper around the same API implemented in pcsc-lite.so.

This class is introduced in Chilkat v9.5.0.87.

Create/Dispose

var
myObject: HCkSCard;

begin
myObject := CkSCard_Create();

// ...

CkSCard_Dispose(myObject);
end;
function CkSCard_Create: HCkSCard; stdcall;

Creates an instance of the HCkSCard object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

procedure CkSCard_Dispose(handle: HCkSCard); stdcall;

Objects created by calling CkSCard_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Properties

ActiveProtocol
procedure CkSCard_getActiveProtocol(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__activeProtocol(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

The name of the active protocol if connected smart card reader, or an empty string if not connected. Possible values are "T0", "T1", "raw", "undefined", or "" if not connected to a reader.

top
CardAtr
procedure CkSCard_getCardAtr(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__cardAtr(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

This is the Current ATR of a card in the connected reader.

top
ConnectedReader
procedure CkSCard_getConnectedReader(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__connectedReader(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

The name of the currently connected smart card reader, or an empty string if not connected.

top
Context
procedure CkSCard_getContext(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__context(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

Contains the string "user" or "system" if this object has established a context (by calling EstablishContext). Contains the empty string if no context is established.

top
DebugLogFilePath
procedure CkSCard_getDebugLogFilePath(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
procedure CkSCard_putDebugLogFilePath(objHandle: HCkSCard; newPropVal: PWideChar); stdcall;
function CkSCard__debugLogFilePath(objHandle: HCkSCard): PWideChar; stdcall;

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

top
LastErrorHtml
procedure CkSCard_getLastErrorHtml(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__lastErrorHtml(objHandle: HCkSCard): PWideChar; stdcall;

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorText
procedure CkSCard_getLastErrorText(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__lastErrorText(objHandle: HCkSCard): PWideChar; stdcall;

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorXml
procedure CkSCard_getLastErrorXml(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__lastErrorXml(objHandle: HCkSCard): PWideChar; stdcall;

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastMethodSuccess
function CkSCard_getLastMethodSuccess(objHandle: HCkSCard): wordbool; stdcall;
procedure CkSCard_putLastMethodSuccess(objHandle: HCkSCard; newPropVal: wordbool); stdcall;
Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of True indicates success, a value of False indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = True and failure = False.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to True. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

top
PcscLibPath
procedure CkSCard_getPcscLibPath(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
procedure CkSCard_putPcscLibPath(objHandle: HCkSCard; newPropVal: PWideChar); stdcall;
function CkSCard__pcscLibPath(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

For Linux systems only. Specifies the full path of the libpcsclite.so shared lib. This property should only be used if the libpcsclite.so is in a non-standard location or if Chilkat cannot automatically located it.

top
ReaderStatus
procedure CkSCard_getReaderStatus(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__readerStatus(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

The current status of the connected reader. Possible values are:

  • "absent" - There is no card in the reader.
  • "present" - There is a card in the reader, but it has not been moved into position for use.
  • "swallowed" - There is a card in the reader in position for use. The card is not powered.
  • "powered" - Power is being provided to the card, but the reader driver is unaware of the mode of the card.
  • "negotiable" - The card has been reset and is awaiting PTS negotiation.
  • "specific" - The card has been reset and specific communication protocols have been established.

top
ScardError
procedure CkSCard_getScardError(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__scardError(objHandle: HCkSCard): PWideChar; stdcall;
Introduced in version 9.50.87

The last error returned by an underlying PC/SC function. Can be one of the following:

  • "SCARD_W_REMOVED_CARD" - The smart card has been removed, so that further communication is not possible.
  • "SCARD_W_RESET_CARD" - The smart card has been reset, so any shared state information is invalid.
  • ...

top
VerboseLogging
function CkSCard_getVerboseLogging(objHandle: HCkSCard): wordbool; stdcall;
procedure CkSCard_putVerboseLogging(objHandle: HCkSCard; newPropVal: wordbool); stdcall;

If set to True, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is False. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
procedure CkSCard_getVersion(objHandle: HCkSCard; outPropVal: HCkString); stdcall;
function CkSCard__version(objHandle: HCkSCard): PWideChar; stdcall;

Version of the component/library, such as "9.5.0.63"

top

Methods

BeginTransaction
function CkSCard_BeginTransaction(objHandle: HCkSCard): wordbool; stdcall;
Introduced in version 9.50.87

Establishes a temporary exclusive access mode for doing a series of commands in a transaction.

Returns True for success, False for failure.

top
CheckStatus
function CkSCard_CheckStatus(objHandle: HCkSCard): wordbool; stdcall;
Introduced in version 9.50.87

Check the current status of the currently connected reader. Calling this method updates the ReaderStatus, ActiveProtocol, and CardAtr properties. If this method returns False, none of the properties are updated.

Returns True for success, False for failure.

top
Connect
function CkSCard_Connect(objHandle: HCkSCard;
    reader: PWideChar;
    shareMode: PWideChar;
    preferredProtocol: PWideChar): wordbool; stdcall;
Introduced in version 9.50.87

Establish a connection to a reader. The reader is the name of a reader returned from ListReaders. The shareMode can be "shared", "exclusive", or "direct". The preferredProtocol can be "0" (valid only if the shareMode = "direct"), "T0", "T1", "raw", or "no_preference". (No preference is effectively T0 or T1.)

If successful, the state of this object instance is that it's connected to the reader.

Returns True for success, False for failure.

top
Disconnect
function CkSCard_Disconnect(objHandle: HCkSCard;
    disposition: PWideChar): wordbool; stdcall;
Introduced in version 9.50.87

Terminates a connection with a reader. The disposition can be one of the following values:

  • "leave": Do nothing.
  • "reset": Reset the card (warm reset).
  • "unpower": Power down the card (cold reset).
  • "eject": Eject the card.

Returns True for success, False for failure.

top
EndTransaction
function CkSCard_EndTransaction(objHandle: HCkSCard;
    disposition: PWideChar): wordbool; stdcall;
Introduced in version 9.50.87

Ends a previously begun transaction. The disposition is the action to be taken on the reader, and can be "leave" which is to do nothing, "reset", "unpower", or "eject".

Returns True for success, False for failure.

top
EstablishContext
function CkSCard_EstablishContext(objHandle: HCkSCard;
    scope: PWideChar): wordbool; stdcall;
Introduced in version 9.5.0.87

Creates an Application Context to the PC/SC Resource Manager. This must be the first WinSCard function called in a PC/SC application. The scope can be "user" or "system". After calling, this object will have context and all other methods will use the established context. The "Context" property will hold the value "user" or "system" if context was established, or will be empty if no context was established.

Returns True for success, False for failure.

top
FindSmartcards
function CkSCard_FindSmartcards(objHandle: HCkSCard;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 9.50.87

Returns JSON containing information about the smartcards currently inserted into readers.

Returns True for success, False for failure.

More Information and Examples
top
GetAttrib
function CkSCard_GetAttrib(objHandle: HCkSCard;
    attr: PWideChar;
    bd: HCkBinData): wordbool; stdcall;
Introduced in version 9.50.87

Get an attribute from the IFD Handler (reader driver).

The attr can be one of the following:

  • "ASYNC_PROTOCOL_TYPES"
  • "ATR_STRING"
  • "CHANNEL_ID"
  • "CHARACTERISTICS"
  • "CURRENT_BWT"
  • "CURRENT_CLK"
  • "CURRENT_CWT"
  • "CURRENT_D"
  • "CURRENT_EBC_ENCODING"
  • "CURRENT_F"
  • "CURRENT_IFSC"
  • "CURRENT_IFSD"
  • "CURRENT_IO_STATE"
  • "CURRENT_N"
  • "CURRENT_PROTOCOL_TYPE"
  • "CURRENT_W"
  • "DEFAULT_CLK"
  • "DEFAULT_DATA_RATE"
  • "DEVICE_FRIENDLY_NAME"
  • "DEVICE_IN_USE"
  • "DEVICE_SYSTEM_NAME"
  • "DEVICE_UNIT"
  • "ESC_AUTHREQUEST"
  • "ESC_CANCEL"
  • "ESC_RESET"
  • "EXTENDED_BWT"
  • "ICC_INTERFACE_STATUS"
  • "ICC_PRESENCE"
  • "ICC_TYPE_PER_ATR"
  • "MAX_CLK"
  • "MAX_DATA_RATE"
  • "MAX_IFSD"
  • "MAXINPUT"
  • "POWER_MGMT_SUPPORT"
  • "SUPRESS_T1_IFS_REQUEST"
  • "SYNC_PROTOCOL_TYPES"
  • "USER_AUTH_INPUT_DEVICE"
  • "USER_TO_CARD_AUTH_DEVICE"
  • "VENDOR_IFD_SERIAL_NO"
  • "VENDOR_IFD_TYPE"
  • "VENDOR_IFD_VERSION"
  • "VENDOR_NAME"

The attribute data is returned in bd.

Returns True for success, False for failure.

top
GetAttribStr
function CkSCard_GetAttribStr(objHandle: HCkSCard;
    attr: PWideChar;
    outStr: HCkString): wordbool; stdcall;
function CkSCard__getAttribStr(objHandle: HCkSCard;
    attr: PWideChar): PWideChar; stdcall;
Introduced in version 9.50.87

Get a string typed attribute from the IFD Handler (reader driver).

The attr can be one of the following, but should be limited to the particular attributes that return string values.

  • "ASYNC_PROTOCOL_TYPES"
  • "ATR_STRING"
  • "CHANNEL_ID"
  • "CHARACTERISTICS"
  • "CURRENT_BWT"
  • "CURRENT_CLK"
  • "CURRENT_CWT"
  • "CURRENT_D"
  • "CURRENT_EBC_ENCODING"
  • "CURRENT_F"
  • "CURRENT_IFSC"
  • "CURRENT_IFSD"
  • "CURRENT_IO_STATE"
  • "CURRENT_N"
  • "CURRENT_PROTOCOL_TYPE"
  • "CURRENT_W"
  • "DEFAULT_CLK"
  • "DEFAULT_DATA_RATE"
  • "DEVICE_FRIENDLY_NAME"
  • "DEVICE_IN_USE"
  • "DEVICE_SYSTEM_NAME"
  • "DEVICE_UNIT"
  • "ESC_AUTHREQUEST"
  • "ESC_CANCEL"
  • "ESC_RESET"
  • "EXTENDED_BWT"
  • "ICC_INTERFACE_STATUS"
  • "ICC_PRESENCE"
  • "ICC_TYPE_PER_ATR"
  • "MAX_CLK"
  • "MAX_DATA_RATE"
  • "MAX_IFSD"
  • "MAXINPUT"
  • "POWER_MGMT_SUPPORT"
  • "SUPRESS_T1_IFS_REQUEST"
  • "SYNC_PROTOCOL_TYPES"
  • "USER_AUTH_INPUT_DEVICE"
  • "USER_TO_CARD_AUTH_DEVICE"
  • "VENDOR_IFD_SERIAL_NO"
  • "VENDOR_IFD_TYPE"
  • "VENDOR_IFD_VERSION"
  • "VENDOR_NAME"

Returns True for success, False for failure.

top
GetAttribUint
function CkSCard_GetAttribUint(objHandle: HCkSCard;
    attr: PWideChar): LongWord; stdcall;
Introduced in version 9.50.87

Get an unsigned integer typed attribute from the IFD Handler (reader driver).

The attr can be one of the following, but should be limited to the particular attributes that return unsigned integer values.

  • "ASYNC_PROTOCOL_TYPES"
  • "ATR_STRING"
  • "CHANNEL_ID"
  • "CHARACTERISTICS"
  • "CURRENT_BWT"
  • "CURRENT_CLK"
  • "CURRENT_CWT"
  • "CURRENT_D"
  • "CURRENT_EBC_ENCODING"
  • "CURRENT_F"
  • "CURRENT_IFSC"
  • "CURRENT_IFSD"
  • "CURRENT_IO_STATE"
  • "CURRENT_N"
  • "CURRENT_PROTOCOL_TYPE"
  • "CURRENT_W"
  • "DEFAULT_CLK"
  • "DEFAULT_DATA_RATE"
  • "DEVICE_FRIENDLY_NAME"
  • "DEVICE_IN_USE"
  • "DEVICE_SYSTEM_NAME"
  • "DEVICE_UNIT"
  • "ESC_AUTHREQUEST"
  • "ESC_CANCEL"
  • "ESC_RESET"
  • "EXTENDED_BWT"
  • "ICC_INTERFACE_STATUS"
  • "ICC_PRESENCE"
  • "ICC_TYPE_PER_ATR"
  • "MAX_CLK"
  • "MAX_DATA_RATE"
  • "MAX_IFSD"
  • "MAXINPUT"
  • "POWER_MGMT_SUPPORT"
  • "SUPRESS_T1_IFS_REQUEST"
  • "SYNC_PROTOCOL_TYPES"
  • "USER_AUTH_INPUT_DEVICE"
  • "USER_TO_CARD_AUTH_DEVICE"
  • "VENDOR_IFD_SERIAL_NO"
  • "VENDOR_IFD_TYPE"
  • "VENDOR_IFD_VERSION"
  • "VENDOR_NAME"

Returns 0xFFFFFFFF on failure.

top
GetStatusChange
function CkSCard_GetStatusChange(objHandle: HCkSCard;
    maxWaitMs: Integer;
    stReaderNames: HCkStringTable;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 9.50.87

Blocks execution until the current availability of the cards in a specific set of readers changes.

This function receives a list of reader names in stReaderNames. It then blocks waiting for a change in state to occur for a maximum blocking time of maxWaitMs (in milliseconds) or forever if 0 is used.

Information about the current reader states and which reader(s) changed is returned in json. See the example below for more information.

To wait for a reader event (reader added or removed) you may use the special reader name "\\?PnP?\Notification".

To cancel the ongoing call, call Cancel().

The stReaderNames contains the reader names to check. The json is empty on input, and if the call returns success contains information about the state (after the event change) of each reader.

Returns True for success, False for failure.

top
GetStatusChangeAsync (1)
function CkSCard_GetStatusChangeAsync(objHandle: HCkSCard;
    maxWaitMs: Integer;
    stReaderNames: HCkStringTable;
    json: HCkJsonObject): HCkTask; stdcall;
Introduced in version 9.50.87

Creates an asynchronous task to call the GetStatusChange method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
GetStatusChangeCancel
function CkSCard_GetStatusChangeCancel(objHandle: HCkSCard): wordbool; stdcall;
Introduced in version 9.50.87

Cancels an ongoing GetStatusChange method call. This would be called from a separate thread in your application if GetStatusChange was called synchronously.

Returns True for success, False for failure.

top
ListReaderGroups
function CkSCard_ListReaderGroups(objHandle: HCkSCard;
    readerGroups: HCkStringTable): wordbool; stdcall;
Introduced in version 9.50.87

Returns a list of currently available reader groups on the system. The reader groups are returned in readerGroups.

Returns True for success, False for failure.

top
ListReaders
function CkSCard_ListReaders(objHandle: HCkSCard;
    st: HCkStringTable): wordbool; stdcall;
Introduced in version 9.50.87

Returns a list of currently available readers on the system.

Returns True for success, False for failure.

More Information and Examples
top
Reconnect
function CkSCard_Reconnect(objHandle: HCkSCard;
    shareMode: PWideChar;
    preferredProtocol: PWideChar;
    action: PWideChar): wordbool; stdcall;
Introduced in version 9.50.87

Reestablishes a connection to a reader that was previously connected to using Connect().

In a multi application environment it is possible for an application to reset the card in shared mode. When this occurs any other application trying to access certain commands will be returned the value SCARD_W_RESET_CARD. When this occurs Reconnect() must be called in order to acknowledge that the card was reset and allow it to change its state accordingly.

The shareMode can be "shared", "exclusive", or "direct". The preferredProtocol can be "0" (valid only if the shareMode = "direct"), "T0", "T1", "raw", or "no_preference". (No preference is effectively T0 or T1.) The action is the desired action taken on the card/reader. It can be "leave", "reset", "unpower", or "eject".

If successful, the state of this object instance is that it's connected to the reader.

Returns True for success, False for failure.

top
ReleaseContext
function CkSCard_ReleaseContext(objHandle: HCkSCard): wordbool; stdcall;
Introduced in version 9.50.87

Destroys a communication context to the PC/SC Resource Manager. This must be the last function called in a PC/SC application.

Returns True for success, False for failure.

top
SendControl
function CkSCard_SendControl(objHandle: HCkSCard;
    controlCode: LongWord;
    bdSend: HCkBinData;
    bdRecv: HCkBinData): wordbool; stdcall;
Introduced in version 9.50.87

Sends a command directly to the IFD Handler (reader driver) to be processed by the reader.

This is useful for creating client side reader drivers for functions like PIN pads, biometrics, or other extensions to the normal smart card reader that are not normally handled by PC/SC.

The command data is sent in bdSend. The response is written to bdRecv.

Returns True for success, False for failure.

top
SendControlHex
function CkSCard_SendControlHex(objHandle: HCkSCard;
    controlCode: LongWord;
    sendData: PWideChar;
    bdRecv: HCkBinData): wordbool; stdcall;
Introduced in version 9.50.87

Sends a command directly to the IFD Handler (reader driver) to be processed by the reader.

This is useful for creating client side reader drivers for functions like PIN pads, biometrics, or other extensions to the normal smart card reader that are not normally handled by PC/SC.

The command data is provided as a hex string in sendData. The response is written to bdRecv.

Returns True for success, False for failure.

top
Transmit
function CkSCard_Transmit(objHandle: HCkSCard;
    protocol: PWideChar;
    bdSend: HCkBinData;
    bdRecv: HCkBinData;
    maxRecvLen: Integer): wordbool; stdcall;
Introduced in version 9.50.87

Sends an APDU to the smart card contained in the currently connected reader. The protocol can be "T0", "T1", or "raw". The APDU to be sent is contained in bdSend. The response from the card is contained in bdRecv. The maxRecvLen is the maximum response size (in bytes) willing to be accepted.

Returns True for success, False for failure.

top
TransmitHex
function CkSCard_TransmitHex(objHandle: HCkSCard;
    protocol: PWideChar;
    apduHex: PWideChar;
    bdRecv: HCkBinData;
    maxRecvLen: Integer): wordbool; stdcall;
Introduced in version 9.50.87

Sends an APDU to the smart card contained in the currently connected reader. The protocol can be "T0", "T1", or "raw". The APDU (in hexadecimal) to be sent is passed in apduHex. The response from the card is contained in bdRecv. The maxRecvLen is the maximum response size (in bytes) willing to be accepted.

Returns True for success, False for failure.

top

Events

Chilkat supports event callbacks for the Delphi DLL starting in version 9.5.0.82.

AbortCheck
function MyAbortCheck(): Integer; cdecl;
Introduced in version 9.5.0.82

Provides the opportunity for a method call to be aborted. The AbortCheck event is fired periodically based on the value of the HeartbeatMs property. If HeartbeatMs is 0, then no AbortCheck events will fire. As an example, to fire 5 AbortCheck events per second, set the HeartbeatMs property equal to 200. Return True to abort; return False to continue (not abort)

More Information and Examples
top
PercentDone
function MyPercentDone(pctDone: Integer): Integer; cdecl;
Introduced in version 9.5.0.82

Provides the percentage completed for any method that involves network communications or time-consuming processing (assuming it is a method where a percentage completion can be measured). This event is only fired when it is possible to know a percentage completion, and when it makes sense to express the operation as a percentage completed. The pctDone argument will have a value from 1 to 100. For operations (Chilkat method calls) that complete very quickly, the number of PercentDone callbacks will vary, but the final callback should have a value of 100. For long running operations, no more than one callback per percentage point will occur (for example: 1, 2, 3, ... 98, 99, 100).

The PercentDone callback counts as an AbortCheck event. For method calls that complete quickly such that PercentDone events fire, it may be that AbortCheck events don't fire because the opportunity to abort is already provided in the PercentDone callback. For time consuming operations, where the amount of time between PercentDone callbacks are long, AbortCheck callbacks may be used to allow for the operation to be aborted in a more responsive manner.

Return True to abort; return False to continue (not abort)

More Information and Examples
top
ProgressInfo
procedure MyProgressInfo(name: PWideChar; value: PWideChar) cdecl;
Introduced in version 9.5.0.82

A general name/value event that provides information about what is happening during a method call. To find out what information is available, write code to handle this event and log the name/value pairs. Most are self-explanatory.

More Information and Examples
top
TaskCompleted
procedure MyTaskCompleted(task: HCkTask) cdecl;
Introduced in version 9.5.0.82

Called in the background thread when an asynchronous task completes.

top