2 messages in net.java.dev.jna.usersProblem with void * ?
FromSent OnAttachments
Shane AyerstApr 16, 2008 10:24 pm 
Timothy WallApr 17, 2008 5:37 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:Problem with void * ?Actions...
From:Shane Ayerst (shan@cognyx.com)
Date:Apr 16, 2008 10:24:23 pm
List:net.java.dev.jna.users

Hello all,

I'm looking for some guidance on using JNA to map a CAN library to java. I have mapped a number of functions successfully however am having trouble with one in particular:

In the C header:

CANLIB_API canStatus __stdcall canWriteWait(CanHandle hnd, long id, void *msgPtr, unsigned int dlc, unsigned int flag, long timeout);

Which I have translated as:

public int canWriteWait(int hnd, long id, byte[] msgPtr, int dlc, int flag, long timeout);

The problem appears to be the msgPtr parameter. When I check the implementation, the msgPtr is pointing to an array of unsigned char, hence the mapping to byte[]. However I am getting an error ('Error in parameter') when using byte:

byte[] mesg = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; CANLibrary.INSTANCE.canWriteWait(0, 10000, mesg, 8, 0, -1);

Example C code using the lib (works fine):

char mesg[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int ret = canWriteWait(0, 10000, mesg, 8, 0, -1);

The only way I can get the call to return correctly is by mapping to Pointer rather than byte[]:

public int canWriteWait(int hnd, long id, Pointer msgPtr, int dlc, int flag, long timeout);

However now I can't see a way of creating the Pointer msgPointer to anything other than Pointer.NULL:

Pointer mesgPtr = Pointer.NULL // ?? How to point to message data ?? CANLibrary.INSTANCE.canWriteWait(0, 0, mesgPtr, 8, 0, -1);

Am I approaching this the right way? Any help would be much appreciated.

Regards, Shane