JNA Struct and Pointer mapping

…衆ロ難τιáo~ 提交于 2020-01-13 09:22:27

问题


How does one map the function below to java?

VOID WriteToStruct(BOOL *Status, STRUCT_MSG RecBuff)

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?


回答1:


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);



回答2:


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



来源:https://stackoverflow.com/questions/494325/jna-struct-and-pointer-mapping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!