C#
  Home arrow C# arrow Page 3 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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 - Two Versions


    (Page 3 of 6 )

    The Microsoft Windows application programming interface (Win32 API) usually contains two versions of every function that handles characters and strings: a 1-byte character ANSI version and a 2-byte character Unicode version. When unspecified, the character set, represented by the CharSet field, defaults to ANSI. Some functions can have more than two versions. You may specify the exact version by providing additional attributes, as in the example below for the MoveFile API’s Unicode version of the function. You may lookup for more explanation on these attributes in the .NET online help.

    [C#]
    [DllImport("KERNEL32.DLL", EntryPoint="MoveFileW",  SetLastError=true,
    CharSet=CharSet.Unicode, ExactSpelling=true,
    CallingConvention=CallingConvention.StdCall)]
    public static extern bool MoveFile(Stringstr src, String strdst);

    A good practice is to group all the related functions in a class and let the class contain all these function prototypes.

    Apart from these function prototypes you’ll also need to provide any Structures’, Unions’, and constants’ definitions because in the .NET FCL these are not available. (For example the POINT structure or the NMHDR structure, if you’re trying to process a Common Control notification in your .NET application.) In the case of our Managed Smart Card Library, we will not be using any callbacks, but if needed you may refer to implementing callbacks in the online help.

    Next comes the point of marshalling. It’s quite important that the .NET runtime understands what we’re trying to pass to the unmanaged function, and what we expect back after its execution. We need to use the Reflection namespace for this purpose, so we may include in our code the following lines:

    [Visual Basic]
    Imports System.Reflection

    [C#]
    using  System.Reflection

    Using this attribute we may specify how the data we pass or expect in return should be treated. You’ll need a bit of time to get used to the types you encounter while making calls to the native API. You may also use the table in the MSDN online help for the table that gives a mapping of the .NET types and the unmanaged types. If you use a third party DLL you must be cautious about these MarshalAs attributes, and use them where required. In most cases you’ll need them.

    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

    - 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...
    - Color Transformation in C# GDI+ Programming
    - Exceptions in C#
    - Overriding versus Overloading
    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway