SCardConnect

The SCardConnect 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(
  IN SCARDCONTEXT hContext,
  IN LPCTSTR szReader,
  IN DWORD dwShareMode,
  IN DWORD dwPreferredProtocols,
  OUT LPSCARDHANDLE phCard,
  OUT LPDWORD pdwActiveProtocol
);
 

Parameters

hContext
Supplies the handle that identifies the resource manager context. The resource manager context is set by a previous call to SCardEstablishContext.
szReader
Supplies the name of the reader containing the target card.
dwShareMode
Supplies a flag that indicates whether other applications may form connections to the card. Possible values are:
Value Meaning
SCARDSHARE_SHARED This application is willing to share the card with other applications.
SCARDSHARE_EXCLUSIVE This application is not willing to share the card with other applications.
SCARDSHARE_DIRECT This application is allocating the reader for its private use, and will be controlling it directly. No other applications are allowed access to it.

dwPreferredProtocols
Supplies a bit mask of acceptable protocols for the connection. Possible values, which may be combined with the OR operation, are:
Value Meaning
SCARD_PROTOCOL_T0 T=0 is an acceptable protocol.
SCARD_PROTOCOL_T1 T=1 is an acceptable protocol.
0 This parameter may be zero only if dwShareMode is set to SCARDSHARE_DIRECT. In this case, no protocol negotiation will be performed by the drivers until an IOCTL_SMARTCARD_SET_PROTOCOL control directive is sent with SCardControl.

phCard
Receives a handle that identifies the connection to the smart card in the designated reader.
pdwActiveProtocol
Receives a flag that indicates the established active protocol. Possible values are:
Value Meaning
SCARD_PROTOCOL_T0 T=0 is the active protocol.
SCARD_PROTOCOL_T1 T=1 is the active protocol.
SCARD_PROTOCOL_UNKNOWN SCARDSHARE_DIRECT has been specified, so that no protocol negotiation has occurred. It is possible that there is no card in the reader.

Return Values

If the function… The return value is…
Succeeds SCARD_S_SUCCESS.
Fails An error code (see Error Codes for a list of all error codes).

Remarks

SCardConnect is a smart card and reader access function. For a description of other access functions, see Smart Card and Reader Access Functions.

QuickInfo

  Windows NT: Use version 4.0 SP3 and later.
  Windows: Use Windows 95 OSR2.1.
  Windows CE: Unsupported.
  Header: Declared in winscard.h.
  Import Library: Link with winscard.lib.

See Also

SCardControl, SCardDisconnect, SCardEstablishContext, SCardReconnect