I am new to JNI. And have a few questions : Can JNI handle every type dll exists in windows? I wanted to link a library but it gives me error. Is it possible JNI and the dll are not compatible?
Excerpt from VB .NET (It works)
Private Declare Function ConnectReader Lib "rfidhid.dll" () As Integer
Private Declare Function DisconnectReader Lib "rfidhid.dll" () As Integer
Private Declare Function SetAntenna Lib "rfidhid.dll" (ByVal mode As Integer) As Integer
Full Code From Java
public class MainForm {
/**
* @param args
*/
public native int ConnectReader();
public static void main(String[] args) {
// TODO Auto-generated method stub
MainForm mf = new MainForm();
System.out.println(mf.ConnectReader());
}
static {
System.loadLibrary("rfidhid");
}
}
Error code shown
Exception in thread "main" java.lang.UnsatisfiedLinkError: MainForm.ConnectReader()I
at MainForm.ConnectReader(Native Method)
at MainForm.main(MainForm.java:13)
Can anyone point to me where I might do wrong?
EDIT:
Turn out I should be doing this (and it works)
import com.sun.jna.Library;
import com.sun.jna.Native;
public class HelloWorld {
public interface MyLibrary extends Library {
public int ConnectReader();
}
public static void main(String[] args) {
Kernel32 lib = (MyLibrary) Native.loadLibrary("rfidhid", MyLibrary.class);
System.out.println(lib.ConnectReader());
}
}