Results 1 to 6 of 6
  1. #1
    burnumd is offline Member
    Join Date
    Apr 2008
    Location
    Indiana
    Posts
    1
    Rep Power
    0

    Default Java Native Access (JNA) return types of void *

    Hi all,

    I'm trying to access a C library in Java and, while going through the various type mappings, I found that one of the functions returns type void *. There didn't appear to be any info on the Java/Native Type Conversions page. Can I safely map to Java's void?

  2. #2
    H_P
    H_P is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Hello burnmd,

    I am also stuck at the same place.

    Though its been really long since you posted the question, I was wondering if you remember the mapping.

    Thanks,

    H

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,440
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by H_P View Post
    Hello burnmd,

    I am also stuck at the same place.

    Though its been really long since you posted the question, I was wondering if you remember the mapping.

    Thanks,

    H
    If anything else fails cast your void* to a jlong. A jlong is a Java long and it is large enough to contain a pointer (on most architectures).

    kind regards,

    Jos

  4. #4
    H_P
    H_P is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Hello JosAH,

    Thank you for your quick response.
    The variable void* xyz, in my the C code, can point to a data array of any size (char, short, int, long, etc.), including structures of data containing different sized members.

    Can I achieve that by using jlong xyz, in jna, where it will be able to point to data array of char, short or a larger data structure?

    Thanks,

    Regards,

    H.

  5. #5
    H_P
    H_P is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    JosAH,
    How is casting *void xyz into Pointer xyz different from casting it into jlong xyz. When would you choose to use Pointer xyz v/s jlong xyz.

  6. #6
    JavaJuJitZu is offline Member
    Join Date
    Jan 2010
    Posts
    26
    Rep Power
    0

    Default

    Hi H_P i think what JOSAH meant was that a pointer essentially contains a numerical memory reference, so a jlong should be able to preserve the information in the void*.

    A quick search I have found an example of the void* being cast to a Pointer and it would seem this is the preferred method.

    Documentation - jnaerator - Behaviour of JNAerator for different inputs - Project Hosting on Google Code
    This is a jna generator if you have the c header files. The documentation explains the tools casting strategy. From what i have read it will translate void* to Pointer as it is the only option.

    I haven't actually played with JNA so take my information as opinion only and perhaps research a little more.
    Last edited by JavaJuJitZu; 01-15-2010 at 12:10 AM. Reason: Disclaimer

Similar Threads

  1. Primitive data types of Java
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-28-2008, 07:29 PM
  2. Data compression at 48 Mbyte/s in native Java
    By rlasse in forum Java Software
    Replies: 0
    Last Post: 03-17-2008, 02:33 AM
  3. Replies: 5
    Last Post: 01-24-2008, 11:53 PM
  4. is void a type?
    By mary in forum New To Java
    Replies: 3
    Last Post: 08-01-2007, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •