简体   繁体   English

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

[英]JNA: How to pass a pointer to a local variable?

I have two local variables: 我有两个局部变量:

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

I need to pass pointers to these variables into (the same named arguments of) a JNA function: 我需要将指向这些变量的指针传递给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);

How? 怎么样?

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

You can't actually "take the address" of a local Java variable. 您实际上不能“获取地址”本地Java变量。 The XByReference types allocate memory for the value in question, and then refer to the address of that memory. XByReference类型为有问题的值分配内存,然后引用该内存的地址。

After the invocation you can call XByReference.getValue() to see any changes to that memory. 调用之后,您可以调用XByReference.getValue()来查看对该内存的任何更改。

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

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