Link to home
Start Free TrialLog in
Avatar of pgiusto
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(threeIntegersClass,"<init>","()V");
   jobject threeIntegers = env->NewObject(threeIntegersClass,constructorID);
   
   // 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 ?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

similar to what u did with the ctor, you need to get the jmethodID of the setter, and then call it

http://java.sun.com/j2se/1.3/docs/guide/jni/spec/functions.doc.html#16656
ASKER CERTIFIED SOLUTION
Avatar of alb66
alb66
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pgiusto
pgiusto

ASKER

Thanks. It works perfectly.
;-)