简体   繁体   中英

How can I convert the following reference variable into Java JNA?

I have the following syntax method in 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);
}

In this method the reference to value. How can I define that in JNA? I tried declaring as int but it doesn't make any sense. Because in C value returns something while in Java if I declare it as int it means im passing an integer value into the method. So how can I declare this ipj_get_value and how would the value be declared? Please advice.

I tried IntByReference as well. But when I try to get the value using getValue() its always returning 0.

JNA provides IntByReference for passing 32-bit values by reference.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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