JNI send and return an address

M

M. Fernandez

Hi everyone,

I wanted to know if it is possible to modify in JNI a value given as
parameter, such as:

//Point class interface.
JNIEXPORT void JNICALL Java_temporal_RectangleProxy_printPoint
(JNIEnv *env, jobject jobj, jint ptr, jint var)
{
Rectangle* rectangle = (Rectangle*)ptr;
rectangle->point->printPoint();
printf("the given variable: %d\n",var);
var = 3;
}

I would like to modify the value of 'var' such that when I get back to
java, this value has changed.

Obviously, this code doesn't do it, but i would like to know if it is
possible (I don't want to return a value with the function because I
would like to work with jobjectArray with different values in each 'row'
and modify a variable that is given as parameter).

thanks a lot for your help,

MArcelo
 
G

Gordon Beaton

I wanted to know if it is possible to modify in JNI a value given as
parameter

No.

You say you want to return a value, yet your method returns void. Why
don't you declare the method to return the value and just return it!
Let the caller do what he wants with it, include reassigning "var":

var = printPoint(ptr, var);

Remember too that native methods belong to the class, and are free to
modify fields in the containing object "this", just like regular java
methods are. If "var" comes from an object field, then you can change
the field value itself directly from the native method (with
SetIntField()).

Consider return a value though, it's both clearer and easier.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JNI return jobjectArray 7
JNI and GetFieldID 12
JNI and pointer deletion 2
JNI generic type of jobject 6
JNI 1
JNI C++ Wrapper 1
JVMTI/JNI and JVMTI_ERROR_INVALID_ENVIRONMENT 2
Problem with JNI 7

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top