Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JNI: Returning a struct from C

Posted on 1997-05-09
2
Medium Priority
?
826 Views
Last Modified: 2006-11-17
I'm using JDK1.1, MSVC++

Say I have a struct in my C program:

struct foo {
        int a;
        int b;
        int *c;
}

(c is an array of ints, length b)

Is there any way using the JNI to return this to Java?

If not, what's the alternative?  Call NewObject, and pass each arg separately to the constuctor?

(code fragment if possible..)

Thanks,

M.
0
Comment
Question by:champine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
aruns earned 200 total points
ID: 1220308
Hi,
Any structure is represented as a class in Java. So, if you have to pass your struct foo, it must be an object. For this you will have to have to have a foo class in Java like :

class foo      
{
      int      a ;
      int[]    c ;

      // Additional lines of code necessary
}

In your native code when your are passing it back, your will have to do two things  :

      1. Create a integer array NewIntArray() JNI call and fill in all the values of c into the array.
      2. Create a new Java foo object with variable a and the new integer array created and pass it back to Java.

In case of any clarifications, please comment.
0
 

Author Comment

by:champine
ID: 1220309
With a code fragment, or even pseudo-code, I'd give it an "A" rating;

0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question