I would recommend Java Native Access (JNA) as its easier than using JNI.
Please find an example (from Wikipedia):
import com.sun.jna.Library;
import com.sun.jna.Native;
public class BeepExampl{
public interface Kernel32 extends Library {
public boolean Beep(int FREQUENCY, int DURATION);
public void Sleep(int DURATION);
}
public static void main(String[] args) {
Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32",
Kernel32.class);
lib.Beep(698, 500);
lib.Sleep(500);
lib.Beep(698, 500);
}
}
Lets say you have a DLL with some functions,
Create an java interface which has the same method signatures as the functions in DLL.
For example
public interface NativeExample{
public int method1(String param1);
public boolean mehthod2();
}
Now following is the way you load the DLL (assuming its name is NativeLib.dll)
NativeExample nativeExample= (NativeExample)Native.loadLibrary("NativeLib", NativeExample.class);
Once you have this, you can call the method from the DLL via java methods.
`nativeExample.method("test");`
`nativeExample.method2();`