简体   繁体   English

typedef struct指向JNA的指针

[英]typedef struct pointer into JNA

I am working on JNA for my application and I am confused about using typedef struct pointer in java. 我正在为我的应用程序在JNA上工作,我对在java中使用typedef结构指针感到困惑。 Please check my code and guide me. 请检查我的代码并指导我。 Thank you in advance! 先感谢您!

Below is my c++ code 下面是我的c ++代码

typedef struct tagHWDeviceInfo
{
USHORT          VendorID;      // vendor id
USHORT          ProductID;     // product id
DWORD           nXExt;         // firmware width
DWORD           nYExt;         // firmware height
DWORD           preesure;      // pressure level
DWORD           penState;      // pen state
}HWDeviceInfo, *PHWDeviceInfo;

and java code 和java代码

public class HWDeviceInfo extends Structure{
    short VendorID;
    short ProductID;
    int   nXExt;        // firmware width
    int   nYExt;        // firmware height
    int   preesure;     // pressure level
    int   penState;
}

Now my question is: what does it mean by *PHWDeviceInfo in c++ code and how can I use this pointer in my java code? 现在我的问题是: c ++代码中的*PHWDeviceInfo 什么意思,我如何在我的java代码中使用这个指针?

JNA automatically converts instances of Structure to struct * in function calls, and to struct in structure field definitions. JNA自动转换的情况下, Structurestruct *函数调用,以及struct的结构字段定义。 Structure.getPointer() gives you the pointer that JNA will use. Structure.getPointer()为您提供JNA将使用的指针。

You can modify this default behavior by tagging your class and/or parameter types with the Structure.ByReference and Structure.ByValue interfaces. 您可以通过使用Structure.ByReferenceStructure.ByValue接口标记类和/或参数类型来修改此默认行为。

JNA documents this clearly as noted by @areeba-irfan-ullah-khan. 正如@ areeba-irfan-ullah-khan所指出的那样,JNA 清楚地记录了这一点

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

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