nxt's place

Tag: jni

JNA: Java Native Access

by on Dec.09, 2007, under Java

If you use JNI to access native code you'll quickly find yourself writing some glue in c/c++ to access the native library. With JNA you can write nice clean code in Java without the need to glue your java code to the native library. This is all done by JNA.

All you need to do is define an interface that  (extends the Library interface and) exposes the methods in the library that you want to access:
import com.sun.jna.*;
// kernel32.dll uses the __stdcall calling convention
// Most C libraries will just extend com.sun.jna.Library
public interface Kernel32 extends StdCallLibrary {
// Method declarations, constant and structure definitions go here
}

Next you load the library using the following code:
Kernel32 kernel32Instance = (Kernel32)
    Native.loadLibrary("kernel32", Kernel32.class);

That's all there is to it, you can now access all methods you defined in the interface.
 Checkout the project page

Comments Off on JNA: Java Native Access :, , , more...

Java for C++

by on Dec.02, 2005, under Java

If you ever tried to use JNI, you might find this utility usefull.
Java for C++ generates c++ wrappers for your java classes to make it easier to use communicate with a c++ application.
According to the freshmeat article, there are still some problems with multidimensional arrays and strings that contain binary data.
But it looks promising.

Comments Off on Java for C++ :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...