5 Replies Latest reply: Feb 13, 2011 1:24 PM by jschellSomeoneStoleMyAlias RSS

    Returning int array from C to Java as method parameter

    839135
      Hello,

      I've been trying to accomplish this

      Java

      int[] myArray = ... (filled with some data);
      int retCode = myNativeCall(myArray);
      if(retCode == 0)
      doSomethingWith(myArray); //myArray gets overwritten with new data (with new size also) during the native call...


      C
      JNIEXPORT jint JNICALL Java_GenChav_rsaEncrypt(JNIEnv *env, jobject obj, jintArray myArray){
      ...
      jintArray outbuf;
      ...
      ...
      int[] new_array = .. // some function will fill this....
      int new_array_length = ...//some function will give me the new size, not big, 512 max...
      jint tmp[new_array_length]; //allocate..need something more ??
      memcpy(tmp, new_array, new_array_lenght);
      ...
      ...
      outbuf=(*env)->NewIntArray(env, new_array_length);
      (*env)->SetIntArrayRegion(env, outbuf, 0, new_array_length, tmp);
      myArray=outbuf;
      ...
      ...

      I tought this way I would have a updated myArray ints on the Java program...

      Any thought??