We help IT Professionals succeed at work.
Get Started

JNI question

pgiusto asked
Last Modified: 2013-11-23
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 ?
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE