JNI send and return an address

Discussion in 'Java' started by M. Fernandez, Apr 5, 2006.

  1. M. Fernandez

    M. Fernandez Guest

    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
     
    M. Fernandez, Apr 5, 2006
    #1
    1. Advertising

  2. On Wed, 05 Apr 2006 18:55:09 +0200, M. Fernandez wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Apr 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5nZWw=?=

    Pass a Web Address and return a File System Address

    =?Utf-8?B?QW5nZWw=?=, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    541
    =?Utf-8?B?U3RldmUgQy4gT3Jy?=
    Sep 21, 2005
  2. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    851
    Alex Hunsley
    Nov 4, 2003
  3. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    906
    Pasturel Jean-Louis
    Mar 3, 2004
  4. vasanth
    Replies:
    0
    Views:
    2,702
    vasanth
    Jan 25, 2005
  5. vasanth
    Replies:
    0
    Views:
    623
    vasanth
    Jan 25, 2005
Loading...

Share This Page