Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Native method problem

Posted on 2000-05-15
4
Medium Priority
?
173 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 80 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

705 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