C#
  Home arrow C# arrow Page 4 - Smart Cards in .NET, Part 2
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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#

Smart Cards in .NET, Part 2
By: Digvijay Chauhan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 32
    2004-11-08

    Table of Contents:
  • Smart Cards in .NET, Part 2
  • The Basics
  • Two Versions
  • The Managed Smart Card Sample
  • Our Interface
  • Points of Interest

  • 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


    Smart Cards in .NET, Part 2 - The Managed Smart Card Sample


    (Page 4 of 6 )

    The following code snippet will let you experiment with the Smart Card reader and the Smart Card directly from the managed code, and you’ll not need to create or use any COM components. But you must be aware of the Smart Card programming APIs with the platform SDK. For a quick start you may want to refer to my previous article of this series, Smart Cards in .NET. (http://www.aspfree.com/c/a/.NET/Smart-Cards-in-.NET/)

    You may also download the demo code for this article here:

    http://images.devshed.com/af/stories/Smart Cards in .NET Part 2/supportfile.zip

    Feel free to modify this code in any way you like.

    First we fire up the Visual Studio .NET IDE and create a new Windows application in C#. Declare the prototypes as below:

    // WinSCard API's to be imported
    [DllImport("WinScard.dll")]
    public static extern int SCardEstablishContext(uint dwScope,
    int nNotUsed1,
    int nNotUsed2,
    ref int phContext);

    [DllImport("WinScard.dll")]
    public static extern int SCardReleaseContext(int phContext);

    [DllImport("WinScard.dll")]
    public static extern int SCardConnect(int hContext,
    string cReaderName,
    uint dwShareMode,
    uint dwPrefProtocol,
    ref int phCard,
    ref int ActiveProtocol);

    [DllImport("WinScard.dll")]
    public static extern int SCardDisconnect(int hCard, int Disposition);

    [DllImport("WinScard.dll")]
    public static extern int SCardListReaderGroups(int hContext,
    ref string cGroups,
    ref int nStringSize);

    [DllImport("WinScard.dll")]
    public static extern int SCardListReaders(int hContext,
    string cGroups,
    ref string cReaderLists,
    ref int nReaderCount);

    [DllImport("WinScard.dll")]
    public static extern int SCardFreeMemory(int hContext,
    string cResourceToFree);

    [DllImport("WinScard.dll")]
    public static extern int SCardGetAttrib(int hContext,
    uint dwAttrId,
    ref byte[] bytRecvAttr,
    ref int nRecLen); 

    These declarations enable us to use these functions as we’d in our unmanaged C++ code.

    More C# Articles
    More By Digvijay Chauhan


       · Hi I'm Digvijay . the author of this article.Please feel free to ask any questions...
       · Dig, I really enjoyed the article. Please keep up the great work!:)
       · awesome! u rok!
       · Hi. Your code won't work if you have more readers connected to one pc. I have...
       · hi,your article was excellent,but u did not provide any code for accessing data...
       · hi i read your article, its very nice.. but there are no code to connect and read...
       · Hi Thiru,Sorry but right now i am away from work in Sweden doing my Masters in...
       · Thanks :-)
       · Hi,Thanks for the fix ... it'll help several people.Regards,DIgvijay
       · hi thanks alot for this lesson.i have some questions please : **** i am...
       · hye.. i already read your article.. it great. its give me an overviw abiut smart...
       · to which file should i paste the following code// WinSCard API's to be...
       · you do the attendance system using smart card ?? so have yuo sucessfully done it??...
       · hi digvijay, sir i want to know a few details about smart cards...i...
       · Hi,Yes i did this about two years ago but right now i am quite busy with my...
       · Hi DigVijay, I read your article, it nice, but i am new to MFC, I have to...
     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT