Solved

JNI: Returning a struct from C

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now