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 ?
JavaJava EE

Avatar of undefined
Last Comment
alb66

8/22/2022 - Mon
Mick Barry

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
alb66

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
pgiusto

Thanks. It works perfectly.
alb66

;-)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy