简体   繁体   中英

JNA Struct and Pointer mapping

How does one map the function below to java?

What this function does:
1) Populates the struct RecBuff
2) Updates status

How do I map to a boolean pointer in Java and access the struct data updated by the function?

I was searching for another issue concerning JNA and structs, and Google redirected me here. I hope this helps.

From JNA API

To pass a structure by value, first define the structure, then define an empty class from that which implements Structure.ByValue. Use the ByValue class as the argument or return type.

 // Original C code typedef struct _Point { int x, y; } Point; Point translate(Point pt, int dx, int dy); // Equivalent JNA mapping class Point extends Structure { public static class ByValue extends Point implements Structure.ByValue { } public int x, y; } Point.ByValue translate(Point.ByValue pt, int x, int y); ... Point.ByValue pt = new Point.ByValue(); Point result = translate(pt, 100, 100); 

You can use the ByReference class to pass values by reference. Presuming BOOL is an int you can use IntegerByReference.

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