Solved

Native method problem

Posted on 2000-05-15
4
171 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
[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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

751 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