2 out of 5 rated this helpful - Rate this topic

SCardListReaders function

Applies to: desktop apps only

The SCardListReaders function provides the list of readers within a set of named reader groups, eliminating duplicates.

The caller supplies a list of reader groups, and receives the list of readers within the named groups. Unrecognized group names are ignored. This function only returns readers within the named groups that are currently attached to the system and available for use.

Syntax

LONG WINAPI SCardListReaders(
  __in      SCARDCONTEXT hContext,
  __in_opt  LPCTSTR mszGroups,
  __out     LPTSTR mszReaders,
  __inout   LPDWORD pcchReaders
);

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 readers is not limited to any context.

mszGroups [in, optional]

Names of the reader groups defined to the system, as a multi-string. Use a NULL value to list all readers in the system (that is, the SCard$AllReaders group).

ValueMeaning
SCARD_ALL_READERS
TEXT("SCard$AllReaders\000")

Group used when no group name is provided when listing readers. Returns a list of all readers, regardless of what group or groups the readers are in.

SCARD_DEFAULT_READERS
TEXT("SCard$DefaultReaders\000")

Default group to which all readers are added when introduced into the system.

SCARD_LOCAL_READERS
TEXT("SCard$LocalReaders\000")

Unused legacy value. This is an internally managed group that cannot be modified by using any reader group APIs. It is intended to be used for enumeration only.

SCARD_SYSTEM_READERS
TEXT("SCard$SystemReaders\000")

Unused legacy value. This is an internally managed group that cannot be modified by using any reader group APIs. It is intended to be used for enumeration only.

 

mszReaders [out]

Multi-string that lists the card readers within the supplied reader groups. If this value is NULL, SCardListReaders ignores the buffer length supplied in pcchReaders, writes the length of the buffer that would have been returned if this parameter had not been NULL to pcchReaders, and returns a success code.

pcchReaders [in, out]

Length of the mszReaders buffer in characters. This parameter receives the actual length of the multi-string structure, including all trailing null characters. If the buffer length is specified as SCARD_AUTOALLOCATE, then mszReaders 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 code/valueDescription
Success
0 (0x0)

SCARD_S_SUCCESS

Group contains no readers
2148532270 (0x8010002E)

SCARD_E_NO_READERS_AVAILABLE

Specified reader is not currently available for use
2148532247 (0x80100017)

SCARD_E_READER_UNAVAILABLE

Other

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

 

Remarks

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

Examples

The following example shows listing the readers.


LPTSTR          pmszReaders = NULL;
LPTSTR          pReader;
LONG            lReturn, lReturn2;
DWORD           cch = SCARD_AUTOALLOCATE;

// Retrieve the list the readers.
// hSC was set by a previous call to SCardEstablishContext.
lReturn = SCardListReaders(hSC,
                           NULL,
                           (LPTSTR)&pmszReaders,
                           &cch );
switch( lReturn )
{
    case SCARD_E_NO_READERS_AVAILABLE:
        printf("Reader is not in groups.\n");
        // Take appropriate action.
        // ...
        break;

    case SCARD_S_SUCCESS:
        // Do something with the multi string of readers.
        // Output the values.
        // A double-null terminates the list of values.
        pReader = pmszReaders;
        while ( '\0' != *pReader )
        {
            // Display the value.
            printf("Reader: %S\n", pReader );
            // Advance to the next value.
            pReader = pReader + wcslen((wchar_t *)pReader) + 1;
        }
        // Free the memory.
        lReturn2 = SCardFreeMemory( hSC,
                                   pmszReaders );
        if ( SCARD_S_SUCCESS != lReturn2 )
            printf("Failed SCardFreeMemory\n");
        break;

default:
        printf("Failed SCardListReaders\n");
        // Take appropriate action.
        // ...
        break;
}


Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winscard.h

Library

Winscard.lib

DLL

Winscard.dll

Unicode and ANSI names

SCardListReadersW (Unicode) and SCardListReadersA (ANSI)

See also

SCardEstablishContext
SCardFreeMemory
SCardGetProviderId
SCardListCards
SCardListInterfaces
SCardListReaderGroups

 

 

Send comments about this topic to Microsoft

Build date: 3/13/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Documentation clarified
The documentation has been clarified from both community comments, published 6/23/2011.
Actually you are both partly correct

Both are defined in scarderr.h:

//
// MessageId: SCARD_E_READER_UNAVAILABLE
//
// MessageText:
//
// The specified reader is not currently available for use.
//
#define SCARD_E_READER_UNAVAILABLE ((DWORD)0x80100017L)


AND

//
// MessageId: SCARD_E_NO_READERS_AVAILABLE
//
// MessageText:
//
// Cannot find a smart card reader.
//
#define SCARD_E_NO_READERS_AVAILABLE ((DWORD)0x8010002EL)


The values are different because the meaning of each error is slightly different. The first means you can't find a smart card, the second is that the specific one you're asking for isn't available.

Previous comment incorrect
This is from WinError.h:

//
// MessageId: SCARD_E_NO_READERS_AVAILABLE
//
// MessageText:
//
// Cannot find a smart card reader.
//
#define SCARD_E_NO_READERS_AVAILABLE _HRESULT_TYPEDEF_(0x8010002EL)
There's no such a thing defined as SCARD_E_NO_READERS_AVAILABLE
It's defined in the header file 'SCARDERR.H' as this: 

//
// MessageId: SCARD_E_READER_UNAVAILABLE
//
// MessageText
//
//  The specified reader is not currently available for use
//
#define SCARD_E_READER_UNAVAILABLE       ((DWORD)0x80100017L)
 
So it's SCARD_E_READER_UNAVAILABLE rather than SCARD_E_NO_READERS_AVAILABLE

Thanks,

Saleh Alsanad