Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following enum how do i map in jna ??

This enum is further referenced in structure.

typedef enum
{
 eFtUsbDeviceNotShared,
 eFtUsbDeviceSharedActive,
 eFtUsbDeviceSharedNotActive,
 eFtUsbDeviceSharedNotPlugged,
 eFtUsbDeviceSharedProblem
} eFtUsbDeviceStatus;

Abdul Khaliq

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
413 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you're using JNA you probably want to explicitly specify the values of the enumeration in Java. By default, Java's basic enum type doesn't really give you that functionality, you have to add a constructor for an EnumSet (see this and this).

A simple way to encode C enumerations is to use public static final const ints wrapped in a class with the same name as the enum. You get most of the functionality you'd get from a Java enum but slightly less overhead to assign values.

Some good JNA examples, including the snippets below (which were copied) are available here.

Suppose your C code looks like:

enum Values {
     First,
     Second,
     Last
};

Then the Java looks like:

public static interface Values {
    public static final int First = 0;
    public static final int Second = 1;
    public static final int Last = 2;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...