JNA (Java Native access) provides a set of Java tool classes for dynamic access to the local system library (native Library: such as window DLL) at runtime without the need to write any native/JNICode. As long as developers describe the functions and structure of the target native library in a Java interface, JNA will automatically map the Java interface to the native function. The following is a sample code for using this tool:
Package com. Sun. JNA. examples;
Import com. Sun. JNA. Library;
Import com. Sun. JNA. Native;
Import com. Sun. JNA. Platform;
/** Simple example of native library declaration and usage .*/
Public class helloworld {
Public interface clibrary extends library {
clibrary instance = (clibrary)
native. loadlibrary (platform. iswindows ()? "Msvcrt": "C"),
clibrary. class);
void printf (string format, object... ARGs);
}
Public static void main (string [] ARGs) {
clibrary. instance. printf ("Hello, world/N");
for (INT I = 0; I clibrary. instance. printf ("argument % d: % s/n", I, argS [I]);
}< BR >}