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