| Start | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| How to call functions in a native library via the JNI interface The Java Native Interface (opens new window) (JNI) allows you to call native functions from Java code, and vice versa. This example shows how to load and call a native function via JNI, it does not go into accessing Java methods and fields from native code using JNI functions (opens new window). Suppose you have a native library named In the JNITest class, declare the function like this: In your native code, define the function like this: The In your Java code, in Note the Call the native function from Java like this: |
||||||||||||||||||||||
| How to call a Java method from native code The Java Native Interface (JNI) allows you to call Java functions from native code. Here is a simple example of how to do it: Java code: Native code: JNI method signature to Java type:
So for our example we used (Z)I - which means the function gets a boolean and returns an int. |
||||||||||||||||||||||
| Utility method in JNI layer This method will help to get the Java string from C++ string. This method will help you to convert jbyteArray to char |
Read Article
https://develop.horje.com/learn/1434/reference