2 messages in net.java.dev.jna.usersRe: [jna-users] How to deal with non ...
FromSent OnAttachments
Daniel HorowitzJun 16, 2007 9:23 am 
Timothy WallJun 16, 2007 4:54 pm 
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] How to deal with non java typesActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jun 16, 2007 4:54:29 pm
List:net.java.dev.jna.users

On Jun 16, 2007, at 12:23 PM, Daniel Horowitz wrote:

How does one deal with types that are not directly supported by java? One of my callbacks must implement an unsigned long in its signature. What type can I use in java so it will be cast properly?

Thanks again, Dan

An unsigned long on windows is 32 bits, so use a java int. An unsigned long on linux may be 32 or 64 bits, so use a NativeLong if you want to run on 64-bit systems or java int if you only care about 32-bit systems.

If you actually need to manipulate the number, you'll need to convert it to a long if you expect the value to exceed 0x7FFFFFFF. Read up on 2s complement arithmetic if you're not sure how. Briefly,

void callback(int arg) { long auto = arg; if (auto < 0) auto = (auto & 0x7FFFFFFF) + 0x80000000L;