Reputation: 768
Using Java and the JNA library, I want to access static methods found within a commercial DLL file (C#).
Unfortunately Java 7 does not allow static methods within an interface, and although Java 8 will amend this the latest beta release appears indifferent.
Suggests/corrections are welcome (I am new to JNA and am avoiding JNI), and I have used Javonet to confirm the method signature.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class INeedHelp {
public interface MyInterface extends Library {
public static boolean isDisconnected(); //Mirror of C# method signature, but wont work
public boolean isDisconnected(); //best fit, but throws exception "Error looking up function 'isDisconnected': The specified procedure could not be found."
}
public static void main(String[] args) {
MyInterface anInstance = (MyInterface) Native.loadLibrary("theDLL", MyInterface.class);
anInstance.isDisconnected();
}
}
Upvotes: 2
Views: 716
Reputation: 180917
You should be able to use Direct Mapping, something like;
import com.sun.jna.*;
public class MyClass {
public static native boolean isDisconnected();
static {
Native.register("theDLL");
}
public static void main(String[] args) {
MyClass.isDisconnected();
}
}
Upvotes: 1