gpt4 book ai didi

java - 如何将以下引用变量转换为 Java JNA?

转载 作者:行者123 更新时间:2023-11-30 15:15:28 29 4
gpt4 key购买 nike

我在 C 中有以下语法方法。

ipj_error ipj_get_value(
ipj_iri_device* iri_device, /**< [in] IRI device data structure */
ipj_key key, /**< [in] Key code to get */
uint32_t* value) /**< [out] Data buffer to store retrieved value */
{
return ipj_get(iri_device, key, 0, 0, value);
}

在此方法中引用值。我如何在 JNA 中定义它?我尝试声明为 int 但没有任何意义。因为在 C 中 value 返回一些东西,而在 Java 中如果我将它声明为 int ,则意味着我将整数值传递到方法中。那么我如何声明这个 ipj_get_value 以及如何声明该值?请指教。

我也尝试过 IntByReference。但是当我尝试使用 getValue() 获取值时,它总是返回 0。

最佳答案

JNA提供IntByReference用于通过引用传递 32 位值。

int passedValue = ...;
IntByReference iref = new IntByReference(passedValue);
lib.invokeMyMethod(iref);
int returnedValue = iref.getValue();

关于java - 如何将以下引用变量转换为 Java JNA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33602369/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com