Solved

Native method problem

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now