1 message in net.java.dev.jna.usersWorks in Linux but not in Windows
FromSent OnAttachments
Gregor B. RosenauerSep 10, 2007 2:20 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Works in Linux but not in WindowsActions...
From:Gregor B. Rosenauer (greg@gmail.com)
Date:Sep 10, 2007 2:20:44 pm
List:net.java.dev.jna.users

I have the sadly-not-so-uncommon problem that I can successfully use JNA under Linux with a 3rd-party closed-source commercial C library (.so) but not in Windows as a .dll

I always get the infamous java.lang.UnsatisfiedLinkError: Cannot locate function 'apiInitLibrary' at com.sun.jna.NativeLibrary.getFunctionAddress(NativeLibrary.java:191) at com.sun.jna.Function.<init>(Function.java:103) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:178) at com.sun.jna.Library$Handler.invoke(Library.java:140) at $Proxy0.apiInitLibrary(Unknown Source)

The lib path is OK, library loads, I even debugged into the JNA-sources - here, function lookup does indeed fail because the function is never added to the lookup-table. Whenever the instruction pointer is supposed to move past the line where the function is added to the Hashmap, it jumps right to the end of the method (?!). However the libary and method name are passed in successfully, as I could verify in Eclipse's debug view.

The header of the library seems to indicate that this is a StdCallLibrary, but all combinations and tips from the list, also the examples did not help. I tried Library, StdCallLibrary, and all combinations of Method-Mappings, a static INSTANCE inside the interface and a local library-handle.

From the header (abbreviated): #if defined(_WIN32) #def... API_WIN32 #ifndef API_DLL #def... API_DLL _declspec(dllexport) #def... API_CALL _stdcall #endif

Here is a function I want to call: (void) init (char* x, char* y, char* z);

On the Java-side, I do: MyLib INSTANCE = (MyLib) Native.loadLibrary("theapi", MyLib.class); myLib.apiInitLibrary(null, null, null);

Again this works perfectly on Linux (Kubuntu 7.0.4 x86, Java5 as well as Java6) but not on WindowsXP SP2 (Java5, 6).

I'd be grateful for any inspiration as I'd need the solution to work primarily under Windows (sadly).

Thanks for this fine project anyway, it is a very elegant solution that saves me from a close encounter with JNI;)

Gregor