Solved

Native method problem

Posted on 2000-05-15
4
167 Views
Last Modified: 2010-04-01
Hi

I have a c language method that returns a pointer to struct (defined in c file) and
I want to use this c language to receive the value of the members of the structure
returned by the 'C' function.I cant use pointers in java.So how could I use the c function
to get the values of the struct returned by the 'C' function

Thanks sridhar
0
Comment
Question by:kesavan_sridhar
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:falter
ID: 2812552
You have to write a wrapper which converts the pointer to an Java Object

The wrapper calls the C-function
- getting the data from the struct
- creating a Java Object
- putting the data into the attributes of the Java object
- return this object to the JVM
0
 

Author Comment

by:kesavan_sridhar
ID: 2815634
To Falter

Helo
Thanks for your response, but is it required to have dependent methods of
a c method to be declared as native method? I mean, if I have a abc() method
of c which I use as a native method
and this abc() method calls some xyz()
method in the c file should I
declare xyz() also as native method
in java file .please explain.


Thanks sridhar
de

0
 
LVL 3

Accepted Solution

by:
falter earned 20 total points
ID: 2816153
No,
you only have to define the native method accessed by Java as a native method in your class.
Methods called inside your JNI code has not to be visible to your Java code.
Think about printf or something else its also a method called and you didn't declare as native Java method.
Also JNI Methods have special Signatures
created by javah from your class.
Like
Java_My_Package_MyClass_nativeMethod

Hope this helps
0
 

Author Comment

by:kesavan_sridhar
ID: 2822078
Thanks very much falter
Bye

sridhar
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
micro services spring boot application error 3 194
github account with ecipse 1 47
HSSFWorkbook cannot be resolved error 10 70
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)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

777 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