【问题标题】:JNA Struct and Pointer mappingJNA 结构和指针映射
【发布时间】:2009-01-30 02:46:56
【问题描述】:

如何将下面的函数映射到java?

VOID WriteToStruct(BOOL *Status, STRUCT_MSG RecBuff)

这个函数的作用:
1) 填充结构 RecBuff
2) 更新状态

如何映射到Java中的布尔指针并访问函数更新的结构数据?

【问题讨论】:

    标签: java jna


    【解决方案1】:

    我正在搜索有关 JNA 和结构的另一个问题,Google 将我重定向到这里。我希望这会有所帮助。

    来自JNA API

    要按值传递结构,首先 定义结构,然后定义一个 实现的空类 结构.按值。使用 ByValue 类作为参数或返回类型。

    // 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】:

      您可以使用 ByReference 类通过引用传递值。假设 BOOL 是一个 int,您可以使用 IntegerByReference。

      【讨论】:

        猜你喜欢
        • 2016-01-11
        • 1970-01-01
        • 2012-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-26
        • 1970-01-01
        相关资源
        最近更新 更多