Smart Cards in .NET - The Code
(Page 5 of 5 )
The ATL COM Component code is self-explanatory, provided you have a fair knowledge of the Microsoft WinSCard.dll API. I’d like to highlight the design I had in my mind.
There is one class CPCSCReader and three other helper classes CReaderSelDlg, CSCEjectDlg and CSCInsertDlg. These work as shown in diagram below:

The SCardLib COM Component
The Smart Card related code, which relies heavily in WinSCard.dll, resides in the CPCSCReader and IPCSCReader interface implemenatation. The workhorse of this component is the following WinSCard.dll exported APIs:
- SCardEstablishContext
- SCardConnect
- SCardStatus
- SCardDisconnect
- SCardTransmit
- The code in Helper Classes is mostly UI related.
At one place in the CReaderSelDlg implementation I needed to find all the available cards, so one WinSCard API (SCardListReaders) has been used there. More details about these API’s can be found in the MSDN.
Points of Interest
There are several advantages if you’re using such an approach to access Smart Cards in .NET. The most visible one is isolation from the WinSCard API with the COM wrapper and the type conversion from Win32 types to .NET types. This is done effectively and precisely by the IDE itself. Any comments and suggestion can be posted to me here.
People have great ideas and sometimes it’s just the implementation that falters. Maybe now with the help of this library and any code derived from it, excellent smart card enabled applications can be developed. I’ll continue to refine this Library and fix any bugs that are reported to me. Hope this helps you roll out your first Smart Card application soon!
See you again in the next article in this series where we’ll develop a completely managed wrapper over WinSCard API.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |