This discussion is archived
2 Replies Latest reply: Dec 26, 2011 2:02 PM by jschellSomeoneStoleMyAlias RSS

JNI callback funtion with multiple arguments

905554 Newbie
Currently Being Moderated
Hi,

Is it possible to return more than one argument in java callback function.

for single arg return, I am using below function in my C code.

jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "(I)V");
(*env)->CallVoidMethod(env, obj, mid, depth);

what are the changes require to return more than one arg?


Thanks in Advance
Ashwani
  • 1. Re: JNI callback funtion with multiple arguments
    EJP Guru
    Currently Being Moderated
    Is it possible to return more than one argument in java callback function.
    Of course. A 'callback function' is just a method like any other.
    what are the changes require to return more than one arg?
    1. Adjust the method declaration in the class you are calling.

    2. Compile the class.

    3. Run javap -s to see the new signature.

    4. Adjust the signature in GetMethod() accordingly in your code.

    5. Adjust the CallVoidMethod() call to pass the necessary parameters.
  • 2. Re: JNI callback funtion with multiple arguments
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    902551 wrote:
    Is it possible to return more than one argument in java callback function.
    Just to be clear you really do mean that you want to call the method with more than one argument?

    Versus a "return" value from the method call of which there can be at most one and which your example has none.


    And for the future you can do anything in JNI that you can do in Java. And the JNI code often looks the same even if it takes more lines to do it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points