2 messages in net.java.dev.jna.usersRe: [jna-users] Problem 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:Re: [jna-users] Problem with void * ?Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Apr 17, 2008 5:37:56 am
List:net.java.dev.jna.users

Native long only maps to Java long on 64-bit *nix. On windows, you can always use Java int; otherwise use NativeLong.

Part of your second argument is taking the place of your pointer argument, and everything else is getting pushed 32 bits down the stack.

On Apr 17, 2008, at 1:24 AM, Shane Ayerst wrote:

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