The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


RE: C Structure and Java

Posted by Kishori Sharan on August 20, 2000 at 12:21 PM

I don't think there is a corresponding java type to C structure so that you can hold the returned value fron C function in java and manipulate it. However, you can get what you want in one of the following ways.
1. You can define a class in java with memeber variables that match the structure of your C structure that you are getting as a return value from your C function. Create a function in C which takes an argument of java object. Call that C function from java passing an object of that class you created and populate the memeber variables of java class in C function with all the data elements of structure that you get in C. This way you can get all the data from C structure into java object.
2. Define a java class with a method which takes a String as an argument. Define a String array as the member object of that class. Pass an object of this class to a C function . Call the method of java class from C function passing the string one at a time which you get in string array in C struture. Keep storing the string in string array instance object of java class within the java class method.
What I mean to say is first you create a C function. You can get the C structure data in the C function you have created. Pass an object of java class to that C function and set the struture data in the instance variables of java object. This way you have all your C struture's data in java object instance variables.



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us