Phone: Espaņa +34 952.60.81.93
Email: sales @ kalysis.com International Voice&Fax: +1 (206) 666 KALY [001 206 666 5259] Mail Address: Plaza de Uncibay, 3 29008 Malaga / Spain
|
|
PC/SC Example - Project Design
This Visual C++ project impliments a simple class called SCardManager. This class defines routines for all of the major
PC/SC functions and does error checking for each. This class also has member variables to store the PC/SC reader list
and a routine to convert PC/SC error codes into text representations.
Class Variables:
m_csReaderList | a string containing a list of null terminated reader
strings set by a call to m_SCardListReaders() (SCardListReaders) |
m_hSC | the SCARD Context (connection to a reader) set by a call to m_SCardEstablishContext( (SCardEstablishContext). This handle is used in subsequent PC/SC calls. |
m_hCardHandle | the SCard Handle (connection to a card) set by a call to m_SCardConnect (SCardConnect). This handle is used in subsequent communication with the card. |
m_SelectedReader | this is a member variable we set aside to store the user selected reader. In PC/SC it is very easy to support multiple readers attached to a single computer and the user can select to which reader they would like to connect. |
Class Routines:
Many of the functions in this module are just wrappers around their counterpart in PC/SC, we add error checking to
the class version. The PC/SC counterpart, if any, is shown in the table below.
m_SCardEstablishContext |
a wrapper around it's PC/SC counterpart SCardEstablishContext
this is the first call made when setting up PC/SC communication. We call this function on object creation.
For more information on SCardEstablishContext, options and return values please see the MSDN documentation for SCardEstablishContext
|
m_SCardListReaders |
a wrapper around it's PC/SC counterpart SCardListReaders
this fuction gets a list of PC/SC readers from the PC/SC Resource Manager and initializes our member variable
m_csReaderList.
For more information on SCardListReaders please see the MSDN documentation for SCardListReaders
|
m_SCardConnect |
a wrapper around it's PC/SC counterpart SCardConnect
this function takes the user selected reader string and opens a connection. We use some basic
options for this function SCARD_SHARE_SHARED means this application is willing to share the card
with other applications, and the SCARD_PROTOCOL* list is just letting the resource manager know
what protocols we will accept. For a complete list of options please see the MSDN documentation for SCardConnect.
|
m_SCardReleaseContext |
a wrapper around it's PC/SC counterpart SCardReleaseContext
this function lets the PC/SC resource manager know that we are done acessing the reader and frees
up any smart card contexts he had established. This call should always be made if an SCardEstablishContext
has succeeded and hence we put it in our object destructor. For more information please see the
MSDN Documentation for SCardReleaseContext
|
m_GetPCSCErrorString |
This function takes a PC/SC error code (LONG) and returns a string representation of that error code.
Very useful for debuggin.
|
M_FillReaderComboBox |
This function takes a pointer to a dialog combobox and fills it with readers from the member object
m_csReaderList.
|
|
|
|
|
|