Search code examples
javadlljna

How to Access 64bit DLLs from Java?


I use JDK (64 bit) and am using the JNA library to access a DLL. However this dll is in C: \ Windows \ SysWWOW64, so it is 64bit. How do I access it? My processor is: 64bits. My JDK is 64bits. My DLL is 64bits.

My Program:

 LibraryMethods libMethods = (LibraryMethods) Native.loadLibrary("msxfs.dll", LibraryMethods.class);

My JNA Interface:

import com.sun.jna.Library;

public interface LibraryMethods extends Library{

     public short WFSStartUp(int dwVersionsRequired, String lpWFSVersion);

}

Error:

java.lang.UnsatisfiedLinkError: %1 is not a valid Win32 application.

Solution

  • If the library is in SysWoW64 then it is 32 bits not 64.

    So you need to use JDK 32 bits to load the DLL.

    You can find more info about SysWow64 in this question