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
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of pgiusto
pgiusto

ASKER

Thanks. It works perfectly.
Avatar of alb66
alb66
Flag of Italy image

;-)
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo