jna 构造函数_如何在JNA中映射枚举

在JNA中映射C语言的枚举类型通常需要在Java中指定枚举值。由于Java的枚举默认不直接提供赋值功能,可以使用包含构造函数的EnumSet或创建一个包含静态常量的类来模拟C的枚举。例如,对于C中的`eFtUsbDeviceStatus`枚举,可以在Java中创建一个类并定义相应的常量。
摘要由CSDN通过智能技术生成

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

解决方案

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值