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

x
?
Solved

Native struct

Posted on 1997-07-07
2
Medium Priority
?
348 Views
Last Modified: 2006-11-17
hi,

I have following question. It would be very nice, if someone can help me.
So I must integrate  native codes in my applet. How can i integarte a complex structure in my java-program.
So i have a complex data type like this
struct XXX(int a,
           *char b,
           *complex_struct c....)
complex_struct is a complex data type like a struct.

So that is not a problem if a have a complex data type
like byte[]. I can translate this to HArrayByte, but what
sould I do, if I have a complex struct like above?

Thanks for any help.

Regards,
Benediktus B. Thie
0
Comment
Question by:irian
[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
 
LVL 2

Expert Comment

by:webster030697
ID: 1222778
I'm not sure how far this will go to answer your question, but hava a look at:

http://www.sd.monash.edu.au/~scott/java/Generic/Lectures/Lecture10/

There are two pages there (3, 4)that deal with native methods, and their implementation.

Good luck!
0
 

Accepted Solution

by:
bare earned 200 total points
ID: 1222779
Hi Irian,
I'll assume that you already know how to handle native methods, otherwise look for it in http://java.sun.com/docs/books/tutorial/native1.1/index.html
This is the best place to learn about how to integrate native code with java code.
Now, to the point, let's say you want to call a native function written in C and you want to send to the function a struct value. What you need to do in your Java code is to initiate a Class that will have all and only the contents of the struct. In you example, what you should do is:
public Class XXX {  // this class is jdk1.1 compatible due to the
   public char c;   // use of inner-classes, but you can avoid it
   public class complex {
      public int x,y;
   }
}

Sending this class after setting the value for the veriables is just like sending a struct value.
When using native methods you need to use the "javah" tool. looking at the .h file you'll see that your .class file is translated to a "struct-like" in the .h file and so a native function can access the java code ....
(this is a brief on the case ....)
Hope I've been helpful.
Have fun,

bare.
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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

670 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