4 messages in net.java.dev.jna.usersRe: [jna-users] Arrays offset
FromSent OnAttachments
Cyril DelmasMar 4, 2009 8:26 am 
Timothy WallMar 4, 2009 8:40 am 
Cyril DelmasMar 4, 2009 8:50 am 
Timothy WallMar 4, 2009 9:35 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] Arrays offsetActions...
From:Timothy Wall (twal@dev.java.net)
Date:Mar 4, 2009 8:40:08 am
List:net.java.dev.jna.users

On Mar 4, 2009, at 11:27 AM, Cyril Delmas wrote:

Hi list, I want to transform this C code :

========== LPBYTE lpImage = (LPBYTE) malloc ( sizeof(BYTE) * 3 * width * height ); // initialize lpImage correctly

ImageTransfer IT; IT.columnBytes = 3; IT.rowBytes = 3 * width; IT.height = height; IT.width = width; IT.data[0] = lpImage+2; // red channel IT.data[1] = lpImage+1; // green channel IT.data[2] = lpImage; // blue channel

// use IT ==========

into the equivalent in Java using JNA.

I don't know which type I must use for "data" in the ImageTransfer structure :

typedef struct { int width; int height; int rowBytes; int columnBytes; unsigned char *data[3]; } ImageTransfer;

and don't know how to initialize the structure in Java (using Pointer, PointerByReference, ByteByReference or ByteBuffer ?). I tried some combinations, without success (access violation).

It's an array of pointers, so use Pointer[] data = new Pointer[3]; what you assign to each pointer depends on your application.