2 messages in net.java.dev.jna.usersRe: [jna-users] NativeLong in a Struc...
FromSent OnAttachments
Francis FernandezApr 14, 2008 9:00 am 
Timothy WallApr 14, 2008 11:27 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] NativeLong in a Structure.ByValueActions...
From:Timothy Wall (twal@dev.java.net)
Date:Apr 14, 2008 11:27:06 am
List:net.java.dev.jna.users

NativeLong implements NativeMapped, and is supported as a structure field, so this is a bug. Please file a bug report on the project page with the offending code (and preferably a JUnit test case).

Indicate the output of "java -jar jna.jar" as well.

If you're only targeting windows, you don't need to use NativeLong, since a native "long" is 32 bits even on 64-bit windows. Also, the "DWORD" in the type implies that the authors intended a 32-bit data field.

On Apr 14, 2008, at 12:00 PM, Francis Fernandez wrote:

I have an API with this struct:

typedef struct _VRmImageFormat { /// width in pixels VRmDWORD m_width; /// height in lines VRmDWORD m_height; /// color format enum VRmColorFormat m_color_format; /// bit combination of enum VRmImageModifier values int m_image_modifier; }VRmImageFormat;

where VRmDWORD is defined as follows:

typedef unsigned long int VRmDWORD;

One of the functions in the API requires a VRmImageFormat be passed by value:

int VRmUsbCamNewImage(VRmImage** fpp_image,VRmImageFormat f_image_format);

My VRmImageFormat class looks like this:

public class VRmImageFormat extends Structure { public static class ByValue extends VRmImageFormat implements Structure.ByValue { } public NativeLong m_width; public NativeLong m_height; //enum VRmColorFormat // { VRM_ARGB_4X8, VRM_BGR_3X8, VRM_RGB_565, VRM_YUYV_4X8, VRM_GRAY_8, VRM_BAYER_GBRG_8, // VRM_BAYER_BGGR_8, VRM_BAYER_RGGB_8, VRM_BAYER_GRBG_8, VRM_GRAY_10, VRM_BAYER_GBRG_10, // VRM_BAYER_BGGR_10, VRM_BAYER_RGGB_10, VRM_BAYER_GRBG_10 } public int m_color_format; public int m_image_modifier; }

At runtime, I receive an error stating

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported structure field type class com.sun.jna.NativeLong at com.sun.jna.Structure$FFIType.get(Structure.java:1198) at com.sun.jna.Structure$FFIType.<init>(Structure.java:1139) at com.sun.jna.Structure$FFIType.get(Structure.java:1188) at com.sun.jna.Structure$FFIType.get(Structure.java:1162) at com.sun.jna.Structure.getTypeInfo(Structure.java:1033) at com.sun.jna.Structure.getTypeInfo(Structure.java:1026) at com.sun.jna.Structure.allocateMemory(Structure.java:217) at com.sun.jna.Structure.<init>(Structure.java:126) at com.sun.jna.Structure.<init>(Structure.java:120) at com.sun.jna.Structure.<init>(Structure.java:116) at structures.VRmImageFormat.<init>(VRmImageFormat.java:15) at structures.VRmImageFormat $ByValue.<init>(VRmImageFormat.java:17) at vrmagic.Capture.main(Capture.java:144)

when I create a VRmImageFormat.ByValue Object. I can't find anywhere in the documentation that explicitly states a NativeLong can't be used in a ByValue Structure, so I wanted to confirm if that was the case. If it is, is there any mapping I can use that will preserve the value and can be used in this type of Object? Thank you for your help.