How to make native method wrapper?

M

Metaphor

Hi all!
I want to make native code wrapper for java.
Then I found JNI, but I need more sample code.

For example, I want JNI to do following things.

1. C++ code makes file pointer.(use fopen())
2. C++ code runs JVM and make it load a class file.
3. This class writes "Hello World!" to the file pointer using fprintf()
wrapper.
4. Then control goes back to C++ code, and it close the pointer.(use
fclose())

Most important thing is that file pointer is exchanged between C++ code
and Java code.
Please give me a sample code or URL informed related things.
 
G

Gordon Beaton

Most important thing is that file pointer is exchanged between C++
code and Java code.

Why is this so important? Why can't the Java code open the necessary
file itself?

If you're just trying to learn how to use the invocation API, have a
look at the sample launcher included with your JDK.

/gordon
 
M

Metaphor

Why is this so important? Why can't the Java code open the necessary
file itself?

File pointer is just a example.
I want to use this to control special handle that is no Java API to
control.(not file handle nor window one)
If you're just trying to learn how to use the invocation API, have a
look at the sample launcher included with your JDK.

Yes, I need Invocation API's example.
But is there more simple and effective sample?
 
G

Gordon Beaton

I want to use this to control special handle that is no Java API to
control.(not file handle nor window one)

If there is no Java API for the handle in question, then *every*
operation involving the handle must be done in native code, not just
creating and destroying it as your example suggests.

However this issue is completely unrelated to invocation; you don't
need your own custom launcher if this is the only problem you are
trying to solve.
Yes, I need Invocation API's example.
But is there more simple and effective sample?

Have a look at chapter 7:
http://java.sun.com/docs/books/jni/html/titlepage.html

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top