5 messages in net.java.dev.jna.usersRe: [jna-users] Mapping questions
FromSent OnAttachments
Phil BorlinSep 3, 2007 12:16 pm 
Timothy WallSep 3, 2007 12:45 pm 
Phil BorlinSep 4, 2007 10:48 am 
Timothy WallSep 4, 2007 10:55 am 
Phil BorlinSep 4, 2007 11:07 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Mapping questionsActions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 4, 2007 10:55:54 am
List:net.java.dev.jna.users

On Sep 4, 2007, at 1:49 PM, Phil Borlin wrote:

I bit the bullet and got the debugger out and figured out where the i nvalid memory access error was occurring. I don't know why this is the case but I was able to map my first char pointer to a String and the char array to a String, but on my 3rd and 4th char pointers I had to map to Pointer to get rid of the error. Everything is working beautifully now! JNA is really fun to use unlike every other native solution I have ever tried to use.

We've tried hard to make the easy and common things trivial and everything else just a matter of a little more Java code (patterns, not boilerplate). Thanks for the feedback!

char * psz_device; char psz_cachefile[PATH_MAX]; char * psz_block; char * psz_error;

Maps to:

public String psz_device;

public String psz_cachefile; // public String psz_block; public Pointer psz_block; // public String psz_error; public Pointer psz_error;

It all depends on how your native code uses the pointers. String is technically mapped to "const char*", meaning the native code is only going to read the memory. Native writes are ignored, unless they write outside the allocated string, which usually crashes the VM.

What are the psz_block/error parameters for, and how are they used? Did you initialize pointers to pass, or just use "null"?