On Jan 7, 2009, at 7:15 AM, Jorge Nieto-Madrid wrote:
Hi Timothy,
I stopped using JNA for a while. Now I started using it again and
have a trivial question: How do I declare an interface for Non-
native/Custom DLLs?
I know that for all DLLs in C:\windows\system32 I must just extend
StdCallLibrary, like in this code snipset (for Kernel32.dll):
public interface Kernel32 extends StdCallLibrary {
// Method declarations, constant and structure definitions go here
Kernel32 INSTANCE = (Kernel32)
Native.loadLibrary("kernel32", Kernel32.class,
W32API.DEFAULT_OPTIONS);
// Optional: wraps every call to the native library in a
// synchronized block, limiting native calls to one at a time
Kernel32 SYNC_INSTANCE = (Kernel32)
Native.synchronizedLibrary(INSTANCE);
.......
So the vital part is: Native.loadLibrary("kernel32", Kernel32.class,
W32API.DEFAULT_OPTIONS);
Lets assume I have the library Saphira.dll in the path C:\Spahira\
How can define interface for it??
You can use depends.exe to examine the contents of the library
(function names). If you have a C header for it, that will tell you
whether it uses the stdcall or c calling convention. You can probably
omit the options to the loadLibrary call. You should put the dll in
your PATH or in java.library.path, or in jna.library.path.
Native.loadLibrary("Saphira", Saphira.class)