Results 1 to 3 of 3
- 03-16-2012, 03:22 AM #1
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
Stuck on driver porting C's Pointer -> Java's Reference
Hi coffee fans,
.gif)
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.
ThanksMeasuring programming progress by lines of code is like measuring aircraft building progress by weight.
- 03-16-2012, 05:15 PM #2
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-17-2012, 07:30 PM #3
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
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 functionThe problem is: how do you pass a boolean pointer to the class?Java Code:foo(bool* value);
What I have done is declare a class extending import com.sun.jna.ptr.PointerByReference:
The usage:Java Code:public class BooleanByReference extends PointerByReference{ boolean value; }
I started writing C wrappers and stuff when the problem was so simple.Java Code:public static void main (String[] args){ BooleanByReference br = new BooleanByReference(); foo(br); System.out.println(br); //Memory location }Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
Similar Threads
-
simple porting (from c) problem
By Kearnel in forum Advanced JavaReplies: 5Last Post: 01-07-2011, 07:04 PM -
Porting a Netbeans project with .form files to Eclipse
By nds in forum EclipseReplies: 0Last Post: 12-28-2010, 09:05 AM -
New to java and stuck
By xpd259 in forum New To JavaReplies: 2Last Post: 12-12-2010, 09:34 AM -
Stuck new to Java
By Jaguar1998 in forum New To JavaReplies: 3Last Post: 04-09-2010, 12:02 PM -
Porting to a Nokia Device
By David55 in forum CLDC and MIDPReplies: 1Last Post: 06-30-2008, 01:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks