How can I pass Parameters to Main via JNI?
Currently I load my DLL like:
class SharedLibrary {
native void GetBuffer(ByteBuffer Buffer);;
SharedLibrary(String[] exec_args) {
String path = new File(exec_args[0]).getAbsolutePath();
System.load(path); //Load My DLL. I want to Pass this DLL some arguments.
ByteBuffer Foo = ByteBuffer.allocateDirect(.....);
GetBuffer(Foo);
}
}
How can I pass the DLL arguments? I need to pass multiple arguments.
The purpose of loading a library into Java is to fulfill Java methods which are declared with the
nativeattribute, such asnative void methodname(_arguments go here_);. You can declare one or more native methods in a class, but all of them are expected to be defined (using JNI standards) in your DLL. From Java, you call them like any other method (by using whatever arguments are defined for the method).If there are data elements you want the DLL’s initialization entry point to receive, you need to make them static members (or methods) of some class and the DLL needs to know to access that class to get them. This, however, would be quite abnormal and is probably not the best way to perform whatever it is you’re looking to do.