2 messages in net.java.dev.jna.usersRe: [jna-users] Callback does not han...
FromSent OnAttachments
Alex Lam S.L.Aug 23, 2008 3:18 am 
Timothy WallAug 23, 2008 5:20 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] Callback does not handle String or varargsActions...
From:Timothy Wall (twal@dev.java.net)
Date:Aug 23, 2008 5:20:08 am
List:net.java.dev.jna.users

Such a callback is problematic because there is no way for the native callback stub to generically the types of the varargs parameters in order to convert them into java objects or primitives. The type information is (presumably) embedded in the format string, rather than in the objects themselves, and that information isn't available to JNA.

Mapping the second arg to Pointer is actually more accurate, since it represents the position of the arguments on the stack. Since your application knows how to parse the format string, it can walk the argument stack and extract each value appropriately using Pointer.getXXX functions with appropriate offsets. Not particularly elegant, but it should work.

On Aug 23, 2008, at 6:18 AM, Alex Lam S.L. wrote:

Hi there,

For dll functions which have "char *" or "...", I can use String and Java Varargs as method parameters and it works like a charm.

However, when I tried to do the same with Callback:

typedef int (*PFKT) (char *format, ...);

public interface PFKT extends Callback { int callback(String format, Object ... parameters); }

JNA claims that it cannot find the right conversion to "parameters". It would run if I declare "parameters" as Pointer instead, but it is evidently not the best solution.

Any pointers on the issue?