Have
searched this forum, spent a lot of time searching the Internet, and
read numerous articles. Yet, I can not find an example that exposes a
solution to my question. Am hoping the community can help.
There
is a need to pass a Java function pointer to C and then have C call
that function. The Java function has some number of arguments.
JNA's
Function class
(http://jna.java.net/javadoc/com/sun/jna/Function.html)
convinces me that this should be possible without resorting to the
Callback class.
The
application resides on a Linux system.
Can someone point me to
an example of the use of JNA's Function class or otherwise show how
to pass a Java function pointer to C?
Many thanks for any
insights you can offer.
JNA supports supplying Java callbacks to native code. You must define an interface that extends the Callback interface, and define a single callback method with a signature that matches the function pointer required by the native code.
(http://twall.github.com/jna/3.3.0/javadoc/overview-summary.html#callbacks)
Callback myCallback = new MyCallbackType() {
public void invoke(int someArgument) {
System.out.println("Callback called!");
}
};
myNativeFunction(myCallback);