Solved

Native struct

Posted on 1997-07-07
2
339 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
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 100 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

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

18 Experts available now in Live!

Get 1:1 Help Now