Solved

JNI: Returning a struct from C

Posted on 1997-05-09
2
823 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 100 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

630 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