Calling C++ dll from Java

You need to include the Java class name and path in your native code, for example if your native method was declared in Java as:

public class NativeCode {
    public static native boolean CreateSession();
}

and the class path was (for example) com.example.NativeCode you would declare your method in native as follows:

extern "C"
JNIEXPORT jboolean JNICALL Java_com_example_NativeCode_CreateSession(JniEnv* env, jclass clazz)
{
    return JNI_TRUE;
}

All JNI methods have a JNIEnv pointer and class as their first two parameters.

Leave a Comment