2 messages in net.java.dev.jna.usersRe: [jna-users] callbacks
FromSent OnAttachments
Daniel HorowitzJun 14, 2007 7:30 pm 
Timothy WallJun 15, 2007 4:48 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] callbacksActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jun 15, 2007 4:48:00 am
List:net.java.dev.jna.users

On Jun 14, 2007, at 10:31 PM, Daniel Horowitz wrote:

So im trying to implement callbacks to java functions and I have the honor of writing my own dll any which way I like. The problem is that my dll depends on another dll which accepts a group of callbacks as a struct.

How should my C function signature look to accept Java callback methods? Should it be

int consume_callbacks(void *one, void *two, void *three)?

where one two and three are java functions?

I am running in to a wall here because the example uses a predefined callback ( WNDENUMPROC lpEnumFunc ) type which you overide with an interface (interface WNDENUMPROC extends StdCallCallbac ). Should I simulate that instead, and typedef three different types based on void*, then re-create those as interfaces in java with callback methods?

ie

// C code typedef void* one; typedef void* two; typedef void* three;

int consume_callbacks(one my_one, two my_two, three my_three)

//Java code interface one extends Callback { boolean callback(); }

Since the existing DLL uses stdcall callbacks (look at the definition of WNDENUMPROC), you will need to define your callback interface the same way.

While your C function *can* use void*, it is better to use the most specific type you have, which is WNDENUMPROC. You need to declare something of type Callback in your java interface, which effectively gets converted to void* at the interface layer.

I believe one of the w32 API example libraries already has an interface definition for WNDENUMPROC; you should duplicate or use that one. It is critical that your java method interface for the callback be identical w/r/t return type and argument count and type as the C callback definition, or you will crash.