10 messages in net.java.dev.jna.usersRe: [jna-users] Using custom librarie...
FromSent OnAttachments
Jorge Nieto-MadridJan 7, 2009 4:14 am 
Timothy WallJan 7, 2009 5:38 am 
Jorge Nieto-MadridJan 7, 2009 5:55 am 
Timothy WallJan 7, 2009 7:08 am 
Jorge Nieto-MadridJan 7, 2009 8:04 am 
Timothy WallJan 7, 2009 8:09 am 
Jorge Nieto-MadridJan 7, 2009 8:24 am 
Timothy WallJan 7, 2009 12:15 pm 
Jorge Nieto-MadridJan 8, 2009 6:36 am 
Timothy WallJan 8, 2009 6:47 am 
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:Re: [jna-users] Using custom libraries (dll)Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Jan 7, 2009 5:38:24 am
List:net.java.dev.jna.users

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)