Hello,
J try to get fields in a class with JNI. It works for primary types but J have a field whih is an object (class A contains an object class B). How can get a reference to this objet an then call the methods inside it.
Classe Essai_01 contains a method passageA which is defined in a JNI function.
Thans for your answers.
Java:
J try to get fields in a class with JNI. It works for primary types but J have a field whih is an object (class A contains an object class B). How can get a reference to this objet an then call the methods inside it.
Classe Essai_01 contains a method passageA which is defined in a JNI function.
Thans for your answers.
Java:
Code:
public class A {
/**
* @param args
*/
B param1 = new B();
int param2 = 2;
}
Code:
public class B {
int paramB = 2;
}
Code:
public class Essai_01 {
public native void callFunction();
public native void affiche(String msg);
public native void passageA(A obj);
public native void passageB(B obj);
static {
System.loadLibrary("MyDLL");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Essai_01 var = new Essai_01();
A objA = new A();
B objB = new B();
var.callFunction();
var.passageA(objA);
var.passageB(objB);
var.affiche("ma chaine");
}
}
Code:
JNIEXPORT void JNICALL Java_essai_101_Essai_101_passageA
(JNIEnv * env, jobject, jobject obj)
{
printf("Appel fonction JNI passageA\n");
jclass cls = env->GetObjectClass(obj);
jfieldID fid = env->GetFieldID(cls, "param2", "I");
int value = env->GetIntField(obj, fid);
printf("param2toto : %d\n", value);