简体   繁体   中英

typedef struct pointer into JNA

I am working on JNA for my application and I am confused about using typedef struct pointer in java. Please check my code and guide me. Thank you in advance!

Below is my c++ code

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

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?

JNA automatically converts instances of Structure to struct * in function calls, and to struct in structure field definitions. Structure.getPointer() gives you the pointer that JNA will use.

You can modify this default behavior by tagging your class and/or parameter types with the Structure.ByReference and Structure.ByValue interfaces.

JNA documents this clearly as noted by @areeba-irfan-ullah-khan.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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