Search code examples
javawindows32bit-64bitjna

Will the JNA Kernel32 mapping work on a 32-bit machine?


My application includes the following call to JNA's pre-cooked Kernel32 interface:

int processID = Kernel32.INSTANCE.GetCurrentProcessId();

Can I build my application into a JAR using my 64-bit laptop and expect this to work on a 32-bit machine?


Solution

  • Clearly Java compiles to platform-independent byte code, so my question boils down to two sub-questions:

    1. Is the library binding done at compile time or runtime?

    2. Is the Kernel32 interface correctly written to describe both the 32-bit and 64-bit versions of the kernel32.dll file.

    Question 1 was obvious, given some thought. JNA is not distributed with a compiler, so the binding must be done at runtime. This is confirmed by a statement on their GitHub page:

    JNA uses a small JNI library stub to dynamically invoke native code.

    Question 2 is harder to answer, but given that all the types in use appear to be architecture-neutral (int is safe on Windows according to this FAQ entry, all pointers use the WinNT.HANDLE, etc.) then I'm pretty confident it's fine.