#include <winscard.h>
LONG SCardConnect(SCARDCONTEXT hContext,
LPCSTR szReader,
DWORD dwShareMode,
DWORD dwPreferredProtocols,
LPSCARDHANDLE phCard,
LPDWORD pdwActiveProtocol);
| hContext | IN | Connection context to the PC/SC Resource Manager |
| szReader | IN | Reader name to connect to |
| dwShareMode | IN | Mode of connection type: exclusive or shared |
| dwPreferredProtocols | IN | Desired protocol use |
| phCard | OUT | Handle to this connection |
| pdwActiveProtocol | OUT | Established protocol to this connection. |
This function establishes a connection to the friendly name of the reader specified in szReader. The first connection will power up and perform a reset on the card.
| Value of dwShareMode | Meaning |
| SCARD_SHARE_SHARED | This application will allow others to share the reader |
| SCARD_SHARE_EXCLUSIVE | This application will NOT allow others to share the reader |
| SCARD_SHARE_DIRECT | Direct control of the reader, even without a card |
SCARD_SHARE_DIRECT can be used before using SCardControl() to send control commands to the reader even if a card is not present in the reader.
| Value of dwPreferredProtocols | Meaning |
| SCARD_PROTOCOL_T0 | Use the T=0 protocol |
| SCARD_PROTOCOL_T1 | Use the T=1 protocol |
| SCARD_PROTOCOL_RAW | Use with memory type cards |
dwPreferredProtocols is a bit mask of acceptable protocols for the connection. You can use (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1) if you do not have a preferred protocol.
SCARDCONTEXT hContext;
SCARDHANDLE hCard;
DWORD dwActiveProtocol;
LONG rv;
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
| SCARD_S_SUCCESS | Successful |
| SCARD_E_INVALID_HANDLE | Invalid hContext handle |
| SCARD_E_INVALID_VALUE | Invalid sharing mode, requested protocol, or reader name |
| SCARD_E_NOT_READY | Could not allocate the desired port |
| SCARD_E_READER_UNAVAILABLE | Could not power up the reader or card |
| SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights |
| SCARD_E_UNSUPPORTED_FEATURE | Protocol not supported |
2007-06-17