1 message in net.java.dev.jna.usersRe: [jna-users] Conversion to JNA
FromSent OnAttachments
Timothy WallOct 10, 2007 6:10 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] Conversion to JNAActions...
From:Timothy Wall (twal@dev.java.net)
Date:Oct 10, 2007 6:10:03 am
List:net.java.dev.jna.users

On Oct 10, 2007, at 7:15 AM, Jens Arm wrote:

Hi

First I want to thank you for JNA - It is very nice.

I have tested JNA with a self programmed .so on Linux and it works great.

We aim to please. Or at least to keep it in the bowl.

Now I want to use it for a more complicated .so, but some conversions I do not know:

Do I use in Java for "unsigned long" NativeLong, too?

Yes. It's the same size data, you just have to be careful with values greater than 0x7FFFFFFF.

How do I convert enum's like this to java: typedef enum { OK = 0, FAILED = 1, } ERRORCODE; Must I use for enum, int?

enum is usually an int. you can always write a simple C program that does sizeof(enum_type) to check.

This empty struct struct _DATA; typedef struct _DATA *HANDLE; is it converted like this? public class PEVQ_HANDLE extends Structure { }

It's not an empty struct, it's a forward declaration. Somewhere else is a definition of struct _DATA. If you don't know what's in it, just use a Pointer.

How do I convert the next two lines? #define CALLBACK ERRORCODE LibRun(HANDLE Handle, void (CALLBACK *pInfo)(char *Info));

void (CALLBACK *pInfo)(char *Info) is a callback, which needs to be an interface that implements com.sun.jna.Callback, and declares a single "callback" method. Assuming you define ERRORCODE and HANDLE types, and that the callback is expecting a C string, the following will work:

interface MyCallback extends Callback { void callback(String info); } ERRORCODE LibRun(HANDLE h, MyCallback cb);

It wouldn't hurt to review the ANSI C manual (aka K&R) so that you understand function declarations and macro preprocessing.