java - JNA:如何将指针传递给局部变量?

标签 java pointers jna local-variables

我有两个局部变量:

Pointer output;
int output_len; /* or better `size_t output_len;` */

我需要将这些变量的指针传递到 JNA 函数(相同的命名参数)中:

    public int libcomcom_run_command(
            byte[] input,
            size_t input_len,
            PointerByReference output,
            Pointer output_len,
            byte[] file,
            PointerByReference argv,
            PointerByReference envp,
            int timeout);

如何?

最佳答案

new PointerByReference(pointerValue);
new IntByReference(intValue);

您实际上无法“获取本地 Java 变量的地址”。 XByReference 类型为相关值分配内存,然后引用该内存的地址。

调用后,您可以调用 XByReference.getValue() 以查看该内存的任何更改。

关于java - JNA:如何将指针传递给局部变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48531209/

相关文章:

java - Spring Boot 不会在 Postgres 中创建表

c - 我不明白以下指针变量声明在 c 中的含义

将结构指针转换为另一个嵌入结构

c - 在取消引用之前为未初始化的指针赋值

java - java中指向函数的指针

java - JNA - 读取多个按键

java - <<=运算符在Java中是什么意思?

java - 如何在 ConstraintValidator 中使用 @Autowired?

java - Java中的Json : How to extract list of subelements?

java - JNA native 函数调用和具有 Double**-Pointer/Array 内存分配的结构