1

my question is: is there any good solution to write a wrapper function that recieves variable arguments, can use those arguments but can also pass them to any jni callmethod-function? I have already tried out stuff like variadic functions. I have managed to recieve variable arguments from functions but i have not managed to pass those variable arguments to any further jni method function. I realy can't find help on the Internet on this Topic. Hope you could help me.

void convertParameterString(JNIEnv *env,... ){
  using namespace std;
  va_list args;
  va_start(args,env);

  jclass cls2 = env->FindClass("CPPJava");//de/xcc/jnitest/JNITest");  // try to find the class 
   if(cls2 == nullptr) {
       cerr << "ERROR: class not found !";
   }
   else {                                  // if class found, continue


       // rerun object construction and method call
       jmethodID ctor = env->GetMethodID(cls2, "<init>", "()V");  // FIND AN OBJECT CONSTRUCTOR 
       if(ctor == nullptr) {
           cerr << "ERROR: constructor not found !" << endl;
       }
       else {
           cout << "Object succesfully constructed !" << endl;
           jobject myo = env->NewObject(cls2, ctor);              // CREEATE OBJECT
           if(myo) {                                     // IF OBJECT CREATED EXECUTE METHOD
               jmethodID show = env->GetMethodID(cls2, "getString", "(I)V");

               if(show == nullptr)
                   cerr << "No showId method !!" << endl;
               else env->CallVoidMethod(myo,show,args);
               cout << "===End of call to java===========" << endl;
           }
       }
   }                   

}

Ben
  • 21
  • 2
  • `va_list` and `va_start` are purely C++ inventions. Not only that, different compilers implement each differently. So your attempt would never work. – PaulMcKenzie Aug 23 '17 at 14:22
  • see https://stackoverflow.com/questions/8880404/how-call-java-vararg-method-from-c-with-valist – Zaboj Campula Aug 23 '17 at 15:51

0 Answers0