64-Bit MyKad Reader Application Source Code

First of all, proceed to download the MyKad Reader Application Source Code (VB.NET) for 32-bit from:

http://www.yasin.my/blog/son_mykad_reader

http://mykad.codeplex.com/

The code is meant for 32-bit platform - it is compatible with Visual Studio 2008 onwards.

To support 64-bit platform, a few modifications are required.


The idea is to change all Handle type parameters to IntPtr instead of Int32

Refer to the following image for illustration:


Is that simple, save it and recompile.

I have tested this code and it supports HID Omnikey 3121 smart card reader on Windows 10 Pro 64-bit.

Why IntPtr ?

Refer to the following knowledgebase from Microsoft, it was quoted that:

https://msdn.microsoft.com/en-us/library/ms973190.aspx

Making all data types 64 bits in length would waste space, because most applications do not need the increased size. However, applications do need pointers to 64-bit data, and they need the ability to have 64-bit data types in selected cases. These considerations led the Windows team to select an abstract data model called LLP64 (or P64). In the LLP64 data model, only pointers expand to 64 bits; all other basic data types (integer and long) remain 32 bits in length.

The .NET CLR for 64-bit platforms uses the same LLP64 abstract data model. In .NET there is an integral data type, not widely known, that is specifically designated to hold 'pointer' information: IntPtr whose size is dependent on the platform (e.g., 32-bit or 64-bit) it is running on.

Other relevant discussion threads found in the Internet:

1.) Using the code targeting 32-bit on 64-bit platform, the scardconnect will returns 6 instead of zero.

https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/3efbabeb-ccc7-44c1-b7ed-f4c8e56844ec/help-with-scardconnect-for-vista-64-bit?forum=windowssecurity

2.) http://stackoverflow.com/questions/10635738/error-invalid-handle-in-net-app-with-winscard-dll

3.) Using OpenSC library.

https://github.com/OpenSC/OpenSC/wiki/Malaysian-MyKAD

Dedicated to the spirit of open source and open society - happy coding !!!

Comments

Adrian Wong said…
Tried it on Windows 7 64bit with ACR38U-N1 Smart Card Reader Not Working.


retval = SCardTransmit(hCard, pciT0, Cmd1, 15, pciT0, Buffer, dLength)
MsgBox(retval)

The code above return "6". Any idea?
Brandon Teoh said…
Hi Adrian.

The source code is 32-bit only.

If you want to run it on 64-bit machine without modification as explained in the blog, you have to compiled the exe as 32-bit, do not compile it as AnyCPU or 64-bit.

From my experience, based on the original source code, when the exe is not compiled as 32-bit retval=6.

According to the following url, returned 6 means ERROR_INVALID_HANDLE.

https://stackoverflow.com/questions/16686685/error-6-when-connecting-gemalto-smart-card

Email me directly for discussion.
Jason Sixface said…
Hi Brandon,
All the links for source code is dead. Could not download. Is there c code version?
thanks

jason
Brandon Teoh said…
Hi jason sixface,

I found that the links are still working though.

You may try to download it here.

https://codeplexarchive.blob.core.windows.net/archive/projects/mykad/mykad.zip

I haven't come across any C code version yet.

You may email me for further discussion.

Jason Sixface said…
Hi brandon,
thanks for the quick reply.
Will check the link.