Specifications
Smart Cards Lab COMPGA12 University College London
17 How to Become a Smart Card Developer
Any student vaguely familiar with Microsoft Visual Studio should be able
start developing smart card applications in 10 minutes. Below we explain
how and give example source code. More examples are found in the files
provided to students.
17.1 How to Send and Receive Commands
In fact, very little is needed to make an application that is able to communi-
cate with a smart card, everything is implemented in a Microsoft winscard
library and winscard.dll which is included by default in all modern versions
of Windows and does not require any installation.
To use it we need the following two lines:
#include "winscard.h"
#pragma comment(lib, "winscard.lib")
This will give us PC/SC Support in our program: we will have access
to functions such as SCardConnect, SCardBeginTransaction, SCardStatus,
SCardTransmit etc. A number of examples on how to use these functions is
given in the Microsoft MSDN documentation. However this documentation
is insufficient to produce working code. in fact these instructions need to
be used in a certain sequence in order to work properly. In the most recent
book about Smart Cards edited by Keith Mayes et al from Royal Holloway,
authors provide a short example source code showing the right sequence.
However the code in the printed version of the book is incorrect and has
several bugs that are not easy to fix. We give a corrected version below.
//written by NCourtois based on MSDN help files
//and RHUL 2006 book example code (none worked initially)
#include "winscard.h"
#pragma comment(lib, "winscard.lib")
typedef unsigned int ui32;
#define PCSC_ERROR(rv, text) \
if (rv != SCARD_S_SUCCESS) \
{ \
printf(text ": %s (0x%lX)\n", pcsc_stringify_error(rv), rv); \
} \
else \
c
Nicolas T. Courtois 2009-10










