JNA:如何将指针传递给局部变量?
JNA: How to pass a pointer to a local variable?
我有两个局部变量:
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);
您实际上不能 "take the address" 局部 Java 变量。 XByReference
类型为相关值分配内存,然后引用该内存的地址。
调用后,您可以调用 XByReference.getValue()
来查看对该内存的任何更改。
我有两个局部变量:
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);
您实际上不能 "take the address" 局部 Java 变量。 XByReference
类型为相关值分配内存,然后引用该内存的地址。
调用后,您可以调用 XByReference.getValue()
来查看对该内存的任何更改。