C++
  Home arrow C++ arrow Page 3 - Writing a Smart Card Library
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Writing a Smart Card Library
By: Digvijay Chauhan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 96
    2004-04-26

    Table of Contents:
  • Writing a Smart Card Library
  • The Approach
  • The CPCSCReader Class
  • The CRegListDlg Class
  • The Demo Application: SCardDemo

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Writing a Smart Card Library - The CPCSCReader Class


    (Page 3 of 5 )

    The class snapshot above gives us the clear picture of what it encapsulates and what methods we can invoke to communicate with the physical reader and the inserted card. In order to open a physical reader you must know the name with which it's configured. I've assumed in code that it's stored in the registry at the key:

    HKEY_CURRENT_USERDSCPCSCReader as in the snapshot below:

    Writing a Smart Card Reader
    Figure 3: The CPCSReader class and Members

    You can always modify the code to suit your need and requirements. It's just meant to be a demonstration and you are free to evolve it in any way you like. You can double click the RegReader.reg file to make the keys and alter them as you like.

    CPCSCReader members

    int OpenReader(CString&)
    This method opens the reader specified by the CString parameter, which holds the name of the reader to be opened. The return value is an int with the following meanings

    Call StatusCard StatusReader Status
    0Reader not opened : FailedCard is not insertedReader is not powered on
    1Reader Opened SuccessfullyCard is insertedReader is powered on
    3Reader Opened SuccessfullyCard is insertedReader is not powered on
    4Reader Opened SuccessfullyCard is insertedreader is powered on

    int CloseReader(CString& strReaderName)
    It Closes the Reader Opened earlier by a call to OpenReader.The return value is either 0 or 1 indicating success or failure. Zero means failure because the Context could not be released and one means that the context was released successfully and that the reader closed successfully and it also asserts that that no card is present and reader is not powered on.

    void SendCommandToCard(CPCSCCommand&)
    This is the workhorse of the whole library and wraps the raw API SCardTransmit. It takes CPCSCCommand reference as parameter and the response is returned in that too.

    BOOL SendCommandToCard(CString&, CString&)
    Same as above but for ease of use takes a CString as Command APDU and returns the response and Status words in another CString.

    void GetReaderStatus()
    It's not actually implemented but one should send a 00 60 10 00 00 as Command and interpret the response from Card.

    BOOL IsCardPresent()
    Returns true if Card is inserted in the reader else returns false.

    BOOL IsReaderPowerd()
    Returns true if Reader is powered on else returns false.

    CString m_strReaderName
    Holds the Reader name with which it was opened. See OpenReader() code for more details.

    int m_bReaderPowerdOn
    This is Boolean member variable to hold the status of power  of reader.

    int m_bCardInserted;
    This is Boolean member variable to hold the card presence status of reader.

    Writing a Smart Card Reader
    Figure 4: The CRed ListDlg class and Members

    More C++ Articles
    More By Digvijay Chauhan


     

    C++ ARTICLES

    - More Tricks to Gain Speed in Programming Con...
    - Easy and Efficient Programming for Contests
    - Preparing For Programming Contests
    - Programming Contests: Why Bother?
    - Polymorphism in C++
    - Overview of Virtual Functions
    - Inheritance in C++
    - Extending the Basic Streams in C++
    - Using Stringstreams in C++
    - Custom Stream Manipulation in C++
    - General Stream Manipulation in C++
    - Serialize Your Class into Streams in C++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT