Results 1 to 3 of 3
  1. #1
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default Stuck on driver porting C's Pointer -> Java's Reference

    Hi coffee fans,
    I am using JNA to call functions from a C driver for a barcode scanner. The prototype functions in the .h file require Pointers (char*,bool*) and I cannot find a way to be able to pass them in Java. I know Java does not use Pointers, but References.

    Is there any way that I could pass something that would act as a pointer? I've tried making objects and passing them in, but it does not work (unless I didn't do it right).

    Any suggestions would be appreciated.

    Thanks
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Stuck on driver porting C's Pointer -> Java's Reference

    I have no experience in JNA/JNI, but once when I wanted to use, from Visual FoxPro, an ActiveX written in C that had similar requirements, I wrote a small C (actually, VC++) wrapper that could accept values and pass on their pointers to the wrapped ActiveX. You could try doing that.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default Re: Stuck on driver porting C's Pointer -> Java's Reference

    Thanks for the help Darryl.

    I would like to share how I have solved the problem just in case any one else happen to have the same problem.

    So I have a C function
    Java Code:
     foo(bool* value);
    The problem is: how do you pass a boolean pointer to the class?

    What I have done is declare a class extending import com.sun.jna.ptr.PointerByReference:

    Java Code:
    public class BooleanByReference extends PointerByReference{
        boolean value;
    }
    The usage:

    Java Code:
    public static void main (String[] args){
     BooleanByReference br = new BooleanByReference();
    
     foo(br);
    
     System.out.println(br); //Memory location
    }
    I started writing C wrappers and stuff when the problem was so simple.
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

Similar Threads

  1. simple porting (from c) problem
    By Kearnel in forum Advanced Java
    Replies: 5
    Last Post: 01-07-2011, 07:04 PM
  2. Replies: 0
    Last Post: 12-28-2010, 09:05 AM
  3. New to java and stuck
    By xpd259 in forum New To Java
    Replies: 2
    Last Post: 12-12-2010, 09:34 AM
  4. Stuck new to Java
    By Jaguar1998 in forum New To Java
    Replies: 3
    Last Post: 04-09-2010, 12:02 PM
  5. Porting to a Nokia Device
    By David55 in forum CLDC and MIDP
    Replies: 1
    Last Post: 06-30-2008, 01:44 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
  •