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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Native struct

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
irian
Asked:
irian
1 Solution
 
webster030697Commented:
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
 
bareCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now