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.