SCardConnect

This function establishes a connection, using a specific resource manager context, between the calling application and a smart card contained by a specific reader. If no card exists in the specified reader, an error is returned.

LONG SCardConnect(
  SCARDCONTEXT hContext, 
  LPCTSTR szReader, 
  DWORD dwShareMode, 
  DWORD dwPreferredProtocols, 
  LPSCARDHANDLE phCard, 
  LPDWORD pdwActiveProtocol 
);

Parameters

  • hContext
    [in] Handle that identifies the resource manager context. The resource manager context is set by a previous call to SCardEstablishContext.
  • szReader
    [in] Null-terminated string that specifies the name of the reader containing the target card.
  • dwShareMode
    [in] Specifies a flag that indicates whether other applications can form connections to the card. The following table shows the possible values for dwShareMode.
    Value Description
    SCARD_SHARE_SHARED Unsupported.
    SCARD_SHARE_EXCLUSIVE This application is not willing to share the card with other applications.
    SCARD_SHARE_DIRECT Unsupported.
  • dwPreferredProtocols
    [in] Specifies a bit mask of acceptable protocols for the connection. The following table shows the possible values, which may be combined with the OR operation, for dwPreferredProtocols.
    Value Description
    SCARD_PROTOCOL_T0 T=0 is an acceptable protocol.
    SCARD_PROTOCOL_T1 T=1 is an acceptable protocol.
    0 This parameter may be 0 only if dwShareMode is set to SCARD_SHARE_DIRECT. In this case, no protocol negotiation is performed by the drivers until an IOCTL_SMARTCARD_SET_PROTOCOL control directive is sent with SCardControl.
  • phCard
    [out] Pointer to a handle that identifies the connection to the smart card in the designated reader.
  • pdwActiveProtocol
    [out] Pointer to a DWORD that receives a flag indicating the established active protocol. The following table shows the possible values for pdwActiveProtocol.
    Value Description
    SCARD_PROTOCOL_T0 T=0 is the active protocol.
    SCARD_PROTOCOL_T1 T=1 is the active protocol.
    SCARD_PROTOCOL_UNKNOWN SCARD_SHARE_DIRECT has been specified, so that no protocol negotiation has occurred. It is possible that there is no card in the reader.

Return Values

The following table shows the possible return values.

Value Description
SCARD_S_SUCCESS Succeeds
An error value (see Smart Card Error Values for a list of all error values). Fails

Remarks

SCardConnect is a smart card and reader access function.

Only one active connection is allowed per context. If a second connection is required, a different context needs to be established and supplied to SCardConnect.

Requirements

OS Versions: Windows CE 3.0 and later.
Header: Winscard.h.
Link Library: Winscard.lib.

See Also

SCardControl | SCardDisconnect | SCardEstablishContext | SCardReconnect

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.