6.4. Calling Java from C++

Once you have crossed the boundary into a native method implementation, you can stay there and do whatever the underlying platform will allow. However, to do anything significant, you will probably need to call back into the virtual machine. Any Java object that is passed into native code appears as an opaque jobject handle, not as a C++ structure or vtable. Therefore, the only way to access fields or methods on a jobject is to call back into the virtual machine through the provided JNIEnv pointer. Also, because the jobject type is opaque at compile time, there is no direct invocation of Java methods or direct access of Java fields. Instead, the JNIEnv* provides a set of functions similar to the Field, Method, and ...

Get Component Development for the Java™ Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.