3 messages in net.java.dev.jna.usersRe: [jna-users] Help with:Callback ar...
FromSent OnAttachments
Scott PalmerApr 7, 2008 8:26 am 
Scott PalmerApr 7, 2008 10:12 am 
Timothy WallApr 7, 2008 10:21 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] Help with:Callback argument class [I requires custom type conversionActions...
From:Timothy Wall (twal@dev.java.net)
Date:Apr 7, 2008 10:21:20 am
List:net.java.dev.jna.users

On Apr 7, 2008, at 11:27 AM, Scott Palmer wrote:

I'm getting :

java.lang.IllegalArgumentException: Callback argument class [I requires custom type conversion

Here is the C code:

typedef void (__cdecl* KMEXT_FPMONITORINGVUMETER)( void *pContext, ULONG *pPeaks, DWORD dwChannels, LONGLONG llTimestamp );

Here is my Java declaration of the callback:

public static interface KMEXT_FPMONITORINGVUMETER extends Callback { void callback(Pointer pContext, int [] pPeaks, int dwChannels, long llTimestamp); } The dwChannels parameter tells me the number of 32-bit ints to expect starting at the address in pPeaks. I could also use a Buffer type instead of an int array, I suppose.. but I think I will still have the problem of dealing with the size of the buffer.

What is the best practice in this situation?

It's easiest to declare pPeaks as Pointer, then extract the int[] from the Pointer using getIntArray. You *could* declare a "FromNative" type converter for "int[]", and examine the FromNativeContext to extract information from the callback invocation, but it's easer just to declare Pointer and extract manually.