Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JNI: Returning a struct from C

Posted on 1997-05-09
2
Medium Priority
?
833 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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

783 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