How do I access java variables from my native code?
1 posts in topic
Flat View  Flat View

Posted By:   Anshul_Malvi
Posted On:   Thursday, June 14, 2001 09:32 AM


I am invoking a java VM from my c++ native code. Iam able to execute a java method on this invoked VM. My question is, is there a way to examine the java variables (arrays etc.) from my native code that have been manipulated by the java method. The variables are global to the corresponding java class?


Re: How do I access java variables from my native code?

Posted By:   Alexander_Krapf  
Posted On:   Friday, June 15, 2001 11:19 AM

Hi Anshul,

I think you mean that the variables are static rather than global. In this case, you have to use the JNI functions for reading values from fields, something along the lines of:

jclass cl = env->FindClass( "MyClass" );
jfieldID fid = env->GetStaticFieldID( cl, "myField", "I" );
jint myField = env->GetStaticIntField( cl, fid );

I omitted a lot of required errorhandling for simplicity sake. You can also have it much more easily by using our JunC++ion product (which unfortunately is not free). Using JunC++ion, you can generate C++ proxy classes for the Java classes that you are interested in and write code like:

jint myField = MyClass::myField;
MyClass::myField += 15;

You can find out more about JunC++ion at http://www.codemesh.com.

Good luck,


About | Sitemap | Contact