Solved

Native method problem

Posted on 2000-05-15
4
168 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

Industry Leaders: 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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

756 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