Solved

JNI: Returning a struct from C

Posted on 1997-05-09
2
817 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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 43
SHA2 certs for IIS AND Java? 2 113
jboss 7.1 start up error 1 41
SequenceInputStream example 3 19
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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…

828 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