简体   繁体   English

JNA Struct和指针映射

[英]JNA Struct and Pointer mapping

How does one map the function below to java? 如何将下面的函数映射到java?

VOID WriteToStruct(BOOL *Status, STRUCT_MSG RecBuff) VOID WriteToStruct(BOOL *状态,STRUCT_MSG RecBuff)

What this function does: 这个功能是做什么的:
1) Populates the struct RecBuff 1)填充结构RecBuff
2) Updates status 2)更新状态

How do I map to a boolean pointer in Java and access the struct data updated by the function? 如何映射到Java中的布尔指针并访问函数更新的struct数据?

I was searching for another issue concerning JNA and structs, and Google redirected me here. 我正在寻找有关JNA和结构的另一个问题,谷歌将我重定向到这里。 I hope this helps. 我希望这有帮助。

From JNA API 来自JNA API

To pass a structure by value, first define the structure, then define an empty class from that which implements Structure.ByValue. 要按值传递结构,首先定义结构,然后从实现Structure.ByValue的类中定义一个空类。 Use the ByValue class as the argument or return type. 使用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); 

You can use the ByReference class to pass values by reference. 您可以使用ByReference类通过引用传递值。 Presuming BOOL is an int you can use IntegerByReference. 假设BOOL是一个int,你可以使用IntegerByReference。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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