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

时间:2015-11-09 04:06:46

标签: java c java-native-interface native jna

我在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值中返回一些东西而在Java中,如果我将其声明为int,则意味着我将整数值传递给方法。那么如何声明这个ipj_get_value以及如何声明该值呢?请指教。

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

1 个答案:

答案 0 :(得分:1)

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

int passedValue = ...;
IntByReference iref = new IntByReference(passedValue);
lib.invokeMyMethod(iref);
int returnedValue = iref.getValue();
相关问题