0

我必须使用 WinScard.dll 库来访问智能卡。我有一个 Java 应用程序,它加载并使用这个库来访问智能卡。

32 位系统:最初我们的应用程序是为 32 位 Windows 编写的。因此,库的以下接口运行良好。

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 位系统:现在,当我们将应用程序迁移到 64 位窗口时,我们意识到要使其工作,我们需要使所有 iHandle 长而不是 int 。因此以下工作

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 . 

所以现在我的问题是:

Scenario 1 :
  • 64 位 Java 虚拟机

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

  • 在 iHandle 界面中保持 Long

处理程序获得:正确

Scenario 2 

(在 64 位系统上运行但使用 32 位工件):

  • 32 位 Java 虚拟机

  • 32位dll

  • 保持长久

获得的处理程序:不正确

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 ?

4

1 回答 1

1
  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.

于 2013-11-13T07:45:03.467 回答