This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How can I pass  a C pointer to a byte array and its length to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can I pass  a C pointer to a byte array and its length to Java " Watch "How can I pass  a C pointer to a byte array and its length to Java " New topic
Author

How can I pass a C pointer to a byte array and its length to Java

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85
Hi,

How can I pass a C pointer to a byte array and its length to Java using JNI?
The example I find are just passing integer. How can I pass a byte array and its length?

Thank you for any pointers.
Adam Michalik
Ranch Hand

Joined: Feb 18, 2008
Posts: 128
This chapter here (see 3.3) says about arrays in the JNI programming. If you want to return byte[] from a Java method (the array will internally have its length, so you don't need to pass it separately), try to compile it with javah and see what comes out. Then, using the methods described in the JNI Programmer's Guide you can convert the C array to a JNI-Java array and return it.
Thank you for any pointers.

Nice pun
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

More suitable for "Other java APIs" forum.
Moving


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I pass a C pointer to a byte array and its length to Java
 
Similar Threads
Memory leaks in Java
What's the best way to pass/return Input/Output streams from Java to JNI?
passing values
Why does getBytes() truncate the string?
How do the values change even if I am not passing the arrays with reference?