4 messages in net.java.dev.jna.users[jna-users] How to create a pointer f...
FromSent OnAttachments
Christine ZimmerJan 13, 2009 2:45 am 
Nikolas LotzJan 13, 2009 5:58 am 
Christine ZimmerJan 14, 2009 11:15 pm 
Nikolas LotzJan 15, 2009 2:41 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] How to create a pointer from byte[]?Actions...
From:Christine Zimmer (chri@gmx.de)
Date:Jan 13, 2009 2:45:39 am
List:net.java.dev.jna.users

Hi,

I'm new to JNA and need your help.

I have a C function:

#define DCSLoadBalancer_Handle void* DCSLoadBalancer_Handle DCSLoadBalancer_FormatDocument (void* pDCSLoadBalancer,
void *pData, long lData, char* pPool, DCSLoadBalancer_Handle hProcessID,
LPDOCUMENTCALLBACK DCSLoadBalancer_DocumentCallback, void* pParam);

The parameter pData has to be a XML string with length lData. In my C
application I call that method this way: ret_id = (hDocID) DCSLoadBalancer_FormatDocument(DCSLoadBalancer,
(void*)text.c_str(), text.length(), NULL, job, NULL,NULL))

The XML string is a c_string that is casted to void*. This works fine.

In my java application I created an interface with: Pointer DCSLoadBalancer_FormatDocument( Pointer pDCSLoadBalancer, String
pData,NativeLong lData,String pPool,Pointer hProcessID,Pointer
callbackfunction,Pointer pParam);

But when I call that method my application aborts prematurely without an error
message. Then I tried it with char[] instead of String, but the application says
'invalid xml'. Then I tried it with byte[] and ByteBuffer and again my
application aborts prematurely without any message.

Maybe I have to create a Pointer? How can I create a Pointer from a byte array?
I tried it with the Pointer.write(...) method, but I get the Exception:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Bounds exceeds
available space : size=1, offset=1669 at com.sun.jna.Memory.boundsCheck(Memory.java:149) at com.sun.jna.Memory.write(Memory.java:271)

One of the parameteres of the Pointer.write(...) method is the offset ('offset -
byte offset from pointer into which data is copied'). What is this offset? I
don't understand the description in the javadoc.

Can anybody help me please?

Christine