JNA Pointer class:如何将 Pointer 对象设置为指向另一个 class?

JNA Pointer class: How to set Pointer object to point to another class?

我正在尝试使用 JNA 库创建单个 Pointer 对象并将其设置为 "point" 定义的自定义数据类型的对象。

有人可以解释一下怎么做吗?

CustomType ctype = new CustomType();
Pointer pointer = new Pointer(ctype);

这不起作用。我尝试过搜索和谷歌搜索,但我找到的 none 个问题显示了我需要的内容。

好的,正如我在评论中所述,解决方案是使自定义数据类型成为具有 getPointer() 方法的 JNA 结构的子类。

使用 com.sun.jna.Structure 的子类并将该对象直接传递给您的映射方法。 JNA 将自动负责同步本机数据并将指向该数据的指针传递给本机方法。

参考 JNA 关于 how to use Structures and the FAQ 的文档。