简体   繁体   English

如何从JNA中的“内存/指针”对象读取结构?

[英]How do I read a structure from a Memory/Pointer object in JNA?

I've been searching for an hour and still haven't found a way to do this. 我已经搜索了一个小时,但仍然没有找到一种方法来执行此操作。 How do I read a structure from a memory/pointer object? 如何从内存/指针对象读取结构? I don't see any methods in Pointer to read a structure, and the only methods of Structure that read from memory are protected. 我没有看到Pointer中的任何方法来读取结构,并且从内存读取的Structure的唯一方法受到保护。 I am trying to use a windows function that takes a pointer to a malloc'd structure array to store PHYSICAL_MONITOR's, which is why I need to do this. 我正在尝试使用Windows函数,该函数需要一个指向malloc的结构数组的指针来存储PHYSICAL_MONITOR,这就是为什么我需要这样做。

Structure defines a Pointer -based constructor. Structure定义了一个基于Pointer的构造函数。

class MyStructure extends Structure {
    public MyStructure() { 
    } 
    public MyStructure(Pointer p) { 
        super(p);
        read();
    } 

See the JavaDoc for Structure for the available options to control how/when Java fields are synched from native memory. 有关可用选项的信息,请参见JavaDoc for Structure ,以控制如何/何时从本机内存同步Java字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM