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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.