3 messages in net.java.dev.jna.users[jna-users] Getting pointers to vario...
FromSent OnAttachments
Drayton BrownApr 29, 2009 7:42 am 
Timothy WallApr 29, 2009 7:51 am 
Drayton BrownApr 29, 2009 8: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:[jna-users] Getting pointers to various offsets in the same memory block.Actions...
From:Drayton Brown (dray@gmail.com)
Date:Apr 29, 2009 7:42:40 am
List:net.java.dev.jna.users

Hi all

I would like to do the following using JNA:

typedef struct { unsigned char *data[3]; } MyStruct;

unsigned char* lpImage; lpImage = (unsigned char*) malloc ( sizeof(unsigned char*) * iNumberOfChannel * iImageWidth, iImageHeight ); //fill the malloc'd memory

MyStruct myStuct; myStuct.data[0] = lpImage;// my red channel myStuct.data[1] = lpImage+1; // my green channel myStuct.data[2] = lpImage+2; // my blue channel

I have tried a couple of things and now I believe this is the closest to what I'm aiming to achieve:

I map the structure as follows:

public static class MyStruct extends Structure public Pointer[] data= new Pointer[3]; }

I then do the malloc equivalent:

Memory memory = new Memory(iNumberOfChannel * iImageWidth, iImageHeight ); //fill the malloc'd memory

Then I set the structure pointers to point to the correct offsets in the malloc'd memory: MyStruct myStruct = new MyStruct();

myStruct.data[0] = memory.getPointer(0) myStruct.data[1] = memory.getPointer(1) myStruct.data[2] = memory.getPointer(2);

Unfortunately when I get the structure back from the function after manipulation, it seems that the data has not been touched!

Please could someone confirm that I have done this correctly, if a nudge in the right direction would be greatly appreciated!

Thanks! Drayton