JNA结构字段值错误
JNA wrong structure field values
我正在围绕JNA适配器"twain.h"跳舞——几乎做到了,但在获得扫描仪功能方面仍然存在一些问题。有一个原始的基因:
typedef unsigned short TW_UINT16, FAR *pTW_UINT16;
typedef unsigned long TW_UINT32, FAR *pTW_UINT32;
typedef struct {
TW_UINT16 ItemType;
TW_UINT32 MinValue; /* Starting value in the range. */
TW_UINT32 MaxValue; /* Final value in the range. */
TW_UINT32 StepSize; /* Increment from MinValue to MaxValue. */
TW_UINT32 DefaultValue; /* Power-up value. */
TW_UINT32 CurrentValue; /* The value that is currently in effect. */
} TW_RANGE, FAR * pTW_RANGE;
这是我的地图(thnx JN曝气器)
public static class TW_RANGE extends Structure {
/** C type : TW_UINT16 */
public short ItemType;
/** C type : TW_UINT32 */
public NativeLong MinValue;
/** C type : TW_UINT32 */
public NativeLong MaxValue;
/** C type : TW_UINT32 */
public NativeLong StepSize;
/** C type : TW_UINT32 */
public NativeLong DefaultValue;
/** C type : TW_UINT32 */
public NativeLong CurrentValue;
public TW_RANGE() {
super();
}
protected List<? > getFieldOrder() {
return Arrays.asList("ItemType", "MinValue", "MaxValue", "StepSize", "DefaultValue", "CurrentValue");
}
}
当我向扫描仪询问这个实体时,扫描仪会向我发送回填充的对象,但当我通过创建它时
new TW_RANGE(pointer)
它还给我一些有线的东西
TwaindsmLibrary$TW_RANGE(native@0x157c000c) (22 bytes) {
short ItemType@0=870
NativeLong MinValue@2=1572916
NativeLong MaxValue@6=5500
NativeLong StepSize@a=2097152
NativeLong DefaultValue@e=5500
NativeLong CurrentValue@12=2621440
}
- 我该如何解读这些价值观
- 我可以转储本机结构并用一些工具进行分析吗?看过Pointer.dump,但它需要转储值的大小,我如何才能得到指针下结构的大小
Structure.read()
才能将本机内存复制到JNA Structure
字段中。
最简单的方法是确保从TW_RANGE(Pointer)
构造函数调用Structure.read()
作为最后一条语句。
JNA通常在进行函数调用时自动调用Structure.read()/write()
。它有意在Structure
构造函数中执行而不是,让程序员决定执行同步的最佳点(如果有的话)。
我搞定了!经过对C++代码的少量调试,我发现(TW_RANGE*)指针和Java一样一团糟。但是(TW_RANGE**)指针的作用就像一个符咒。所以
new TW_RANGE(pointer.getPointer(0))
[掌声]这个解决方案导致我出现随机内存访问错误。我应该使用Twain原生的MemAllocate/Lock/Free函数,它从给定的指针返回正确的值。
相关文章:
- 声明为无效的变量或字段'...' Ardunio 编译器上的错误
- 我正在尝试一个傻瓜 C++ 练习,我遇到了一个错误,说类 'GraduateStudent' 没有任何名为 'advisor' 的字段
- 错误:字段'dateOfBirth'的类型不完整'Poco::Data::Date'
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- 错误:变量或字段'PrintEntity'声明无效无效打印实体(实体 e);
- C++ SPDLOG 编译错误:变量或字段"set_error_handler"声明为无效
- 带有 std::map 的模板函数给出错误:变量或字段声明为 void
- 视觉错误:变量或字段'Palindrome'在 C++ 中声明为 void
- 定义静态类字段时多个已定义符号的链接器错误
- 委托构造函数在使用类字段进行参数时会出现分段错误
- SSE错误 - 使用M128I_I32定义__M128i变量的字段
- 导致IAR ARM中出现错误的成员结构位字段元素的Initializer列表初始化
- 类类型的静态constexpr字段在g++中给出链接时间错误
- 类定义错误 - 字段下一个具有不完整的类型
- G++ 错误:字段的类型不完整
- 错误:字段在C++中具有不完整的类型
- 对象数组参数 - 错误:字段“字母”的类型不完整
- C++类相互引用( => 错误 + 字段"..."类型不完整)
- 错误:字段“m_ssmmap”具有不完整的C++类型
- 结构定义错误:字段' myaiocb '类型不完整