How to pass and return unsigned int by value from Java in C / C ++ to jna

My C ++ function

extern "C" {
   DECLSPEC unsigned int STDCALL doNumberThing(unsigned int some_number);
}

My java interface

package com.myplace.nativeapi;

import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;

interface NativeAPI extends Library {
    int doNumberThing(int some_number);
}

Obviously, this matters when dealing with values ​​that are valid only for one or the other of the inconsistent types (int vs unsigned int); What is the recommended way to get around this? One answer elsewhere recommends "IntByReference", but if I do not understand, they are talking about a long *, and not that the actual unsigned int is passed by value.

(This is a shortened sample code, if there is a syntax error, let me know in the comments and I will update the question)

+4
source share
1 answer

JNA IntegerType, . Java long unsigned int , Java int, IntegerType .

public class UnsignedInt extends IntegerType {
    public UnsignedInt() {
         super(4, true);
    }
}
+4

Source: https://habr.com/ru/post/1614607/


All Articles