Your union members need to be pointer types. By default structure
types are inlined when nested, so you must use Pointer or implement
StructureByReference when used as a structure field.
On Feb 11, 2009, at 1:27 PM, Hendrik Saly wrote:
Hello again,
is it correct to map a C Union
C:
typedef struct test_callback_data
{
unsigned int type;
union specific_data
{
test__DATA *test_data;
test_XX_DATA *data;
} callback_data;
} test_CALLBACK_DATA;
to Java using JNA in that way:
Java:
public static class test_callback_data extends Structure
{
public int type;
public UNION_callback_data callback_data;
}
public static class UNION_callback_data extends Union
{
public test__DATA test_data;
public test_XX_DATA data;
}
public interface CALLBACK extends com.sun.jna.Callback
{
int callback(test_callback_data data);
}
The Union is filled by a callback function. The instance fields are
then always 0 or null, so i guess they get not properly initialised.
How to use the setType(Class clazz) method in/with the Union? Should
i use or override the method?
Environment: Linux i386, JNA 3.0.5, Sun JDK 1.5
Thanks
Hendrik