pgiusto
asked on
JNI question
Hi, I'm using jni to access a win32 dll.
The dll has one method that receives 3 int pointers and set them with values.
So I have to call the function and then return this values to my java program.
So the code look like this:
JNIEXPORT jobject JNICALL MyWrappedFunction(JNIEnv * env, jobject jobj)
{
int a;
int b;
int c;
MyDllFunction (&a, &b, &c); // this is the call to the dll' function
jclass threeIntegersClass = env->FindClass ("bla/bla/ThreeIntegers")
jmethodID constructorID = env->GetMethodID(threeInte gersClass, "<init>"," ()V");
jobject threeIntegers = env->NewObject(threeIntege rsClass,co nstructorI D);
// don't know what to do next !!!
return null;
}
And in my Java program I have this class:
class ThreeIntegers {
public int one;
public int two;
public int three;
public ThreeIntegers() {
}
}
So I know how to construct muy "Java object" inside my C++ code, but don't know how to set the attributes values. I mean, I wan't to do something like this:
threeIntegers.setAttribute ("one", &a);
threeIntegers.setAttribute ("two", &b);
threeIntegers.setAttribute ("three", &c);
Can you help me ?
The dll has one method that receives 3 int pointers and set them with values.
So I have to call the function and then return this values to my java program.
So the code look like this:
JNIEXPORT jobject JNICALL MyWrappedFunction(JNIEnv * env, jobject jobj)
{
int a;
int b;
int c;
MyDllFunction (&a, &b, &c); // this is the call to the dll' function
jclass threeIntegersClass = env->FindClass ("bla/bla/ThreeIntegers")
jmethodID constructorID = env->GetMethodID(threeInte
jobject threeIntegers = env->NewObject(threeIntege
// don't know what to do next !!!
return null;
}
And in my Java program I have this class:
class ThreeIntegers {
public int one;
public int two;
public int three;
public ThreeIntegers() {
}
}
So I know how to construct muy "Java object" inside my C++ code, but don't know how to set the attributes values. I mean, I wan't to do something like this:
threeIntegers.setAttribute
threeIntegers.setAttribute
threeIntegers.setAttribute
Can you help me ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. It works perfectly.
;-)
http://java.sun.com/j2se/1.3/docs/guide/jni/spec/functions.doc.html#16656