JNA结构和指针映射 [英] JNA Struct and Pointer mapping

查看:271
本文介绍了JNA结构和指针映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将下面的功能映射到Java?

How does one map the function below to java?

无效的WriteToStruct(BOOL *状态,STRUCT_MSG RecBuff)

此功能的作用:
1)填充结构RecBuff
2)更新状态

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

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

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

推荐答案

我正在寻找与JNA和结构有关的另一个问题,Google在这里重定向了我.我希望这会有所帮助.

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

来自 JNA API

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

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

这篇关于JNA结构和指针映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆