Question

I have to make use of the WinScard.dll library to access the smart card . I have a Java application that loads and makes use of this library to access the smart card .

32 Bit systems : Initially our application was written for a 32 bit Windows . Hence the following interface to the library worked well .

SCard INSTANCE = (SCard)Native.loadLibrary("C:\\Windows\\SysWOW64\\WinSCard.dll", SCard.class);   

public int SCardEstablishContext(int iScope, Pointer pvReserved1, Pointer pvReserved2, /*OUT &long*/LongByReference rRdrlHandle);    

public int SCardGetStatusChangeA(int iHandle, int dwTimeout, /*IN/OUT*/SCardReaderState.ByReference rgReaderStates, int cReaders);

64 bit systems : Now while we were migrating our application for a 64 bit windows we realised that to make it work we needed to make all the iHandle long intead of int . Thus the following works

SCard INSTANCE = (SCard)Native.loadLibrary("C:\\Windows\\System32\\winscard", SCard.class);

public int SCardEstablishContext(int iScope, Pointer pvReserved1, Pointer pvReserved2, /*OUT &long*/LongByReference rRdrlHandle);

public int SCardGetStatusChangeA(long iHandle, int dwTimeout, /*IN/OUT*/SCardReaderState.ByReference rgReaderStates, int cReaders);



 Note: Point of interest is the first param to the SCardGetStatusChangeA api exposed by the library . 

So now my question is this :

Scenario 1 :
  • 64 bit Java VM

  • 64 bit dll ( C:\Windows\System32 )

  • Keep Long in the interface iHandle

Handler obtained : Correct

Scenario 2 

( running on a 64 bit system but using 32 bit artifacts ) :

  • 32 bit Java VM

  • 32 bit dll

  • Keep Long

Handler obtained : Incorrect

Shouldn't the scenario 2 be taken care automatically by the WOW64 subsystem . I read that WOW64 automatically converts the data structures so that a 32 bit application can run on a 64 bit system .

Can someone advice me on how to get my application running on both 32 & 64 bit systems without having the need to change the interface of the iHandle every time ?

Was it helpful?

Solution

  1. Don’t set an absolute path for the dll. Just require “WinSCard.dll,” and JNA will resolve it to the correct one for the process.
  2. Use a Pointer for iHandle, which is either 32 or 64 bits depending on the process. See also all the “Using the Library” links from the JNA readme.

Also consider using JNAerator, which automatically makes JNA interfaces from the headers. If you can get it to work, it can save you a lot of time.

For the WinSCard library, I actually made a cross-platform JNA interface which you can feel free to use or copy, in case you also want to use it with the pcsclite library on Linux or Mac.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top