Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SCardListCards function

The SCardListCards function searches the smart card database and provides a list of named cards previously introduced to the system by the user.

The caller specifies an ATR string, a set of interface identifiers (GUIDs), or both. If both an ATR string and an identifier array are supplied, the cards returned will match the ATR string supplied and support the interfaces specified.

Syntax


LONG WINAPI SCardListCards(
  _In_      SCARDCONTEXT hContext,
  _In_opt_  LPCBYTE pbAtr,
  _In_      LPCGUID rgguidInterfaces,
  _In_      DWORD cguidInterfaceCount,
  _Out_     LPTSTR mszCards,
  _Inout_   LPDWORD pcchCards
);

Parameters

hContext [in]

Handle that identifies the resource manager context for the query. The resource manager context can be set by a previous call to SCardEstablishContext.

If this parameter is set to NULL, the search for cards is not limited to any context.

pbAtr [in, optional]

Address of an ATR string to compare to known cards, or NULL if no ATR matching is to be performed.

rgguidInterfaces [in]

Array of identifiers (GUIDs), or NULL if no interface matching is to be performed. When an array is supplied, a card name will be returned only if all the specified identifiers are supported by the card.

cguidInterfaceCount [in]

Number of entries in the rgguidInterfaces array. If rgguidInterfaces is NULL, then this value is ignored.

mszCards [out]

Multi-string that lists the smart cards found. If this value is NULL, SCardListCards ignores the buffer length supplied in pcchCards, returning the length of the buffer that would have been returned if this parameter had not been NULL to pcchCards and a success code.

pcchCards [in, out]

Length of the mszCards buffer in characters. Receives the actual length of the multi-string structure, including all trailing null characters. If the buffer length is specified as SCARD_AUTOALLOCATE, then mszCards is converted to a pointer to a byte pointer, and receives the address of a block of memory containing the multi-string structure. This block of memory must be deallocated with SCardFreeMemory.

Return value

This function returns different values depending on whether it succeeds or fails.

Return codeDescription
Success

SCARD_S_SUCCESS.

Failure

An error code. For more information, see Smart Card Return Values.

 

Remarks

This function is not redirected, but calling the function when inside a Remote Desktop session will not result in an error. It only means that the result will be from the remote computer instead of the local computer.

To return all smart cards introduced to the subsystem, set pbAtr and rgguidInterfaces to NULL.

The SCardListCards function is a database query function. For more information on other database query functions, see Smart Card Database Query Functions.

Calling this function should be done outside of a transaction. If an application begins a transaction with the SCardBeginTransaction function and then calls this function, it resets the hCard parameter (of type SCARDHANDLE) of the SCardBeginTransaction function.

Windows Server 2008 R2 and Windows 7:  Calling this function within a transaction could result in your computer becoming unresponsive.

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:  Not applicable.

Examples

The following example shows listing of the smart cards.


LPTSTR pmszCards = NULL;
LPTSTR pCard;
LONG lReturn;
DWORD cch = SCARD_AUTOALLOCATE;

// Retrieve the list of cards.
lReturn = SCardListCards(NULL,
                         NULL,
                         NULL,
                         NULL,
                         (LPTSTR)&pmszCards,
                         &cch );
if ( SCARD_S_SUCCESS != lReturn )
{
    printf("Failed SCardListCards\n");
    exit(1); // Or other appropriate error action
}
// Do something with the multi string of cards.
// Output the values.
// A double-null terminates the list of values.
pCard = pmszCards;
while ( '\0' != *pCard )
{
    // Display the value.
    printf("%S\n", pCard );
    // Advance to the next value.
    pCard = pCard + wcslen(pCard) + 1;
}

// Remember to free pmszCards (by calling SCardFreeMemory).
// ...


Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Winscard.h

Library

Winscard.lib

DLL

Winscard.dll

Unicode and ANSI names

SCardListCardsW (Unicode) and SCardListCardsA (ANSI)

See also

SCardEstablishContext
SCardFreeMemory
SCardGetProviderId
SCardListInterfaces
SCardListReaderGroups
SCardListReaders

 

 

Community Additions

Show:
© 2014 Microsoft