How to return a struct by value using JNR?

356 Views Asked by At

I'm trying to work with the openh264 native library from Java code using JNR. The function I'm calling is defined in openh264's C header file to return a simple struct by value:

typedef struct  _tagVersion {
    unsigned int uMajor;
    unsigned int uMinor;
    unsigned int uRevision;
    unsigned int uReserved;
} OpenH264Version;

OpenH264Version WelsGetCodecVersion (void);

I wrote the following Java counterparts:

public class OpenH264Version extends Struct {

    public OpenH264Version(Runtime runtime) {
        super(runtime);
    }

    public Unsigned32 uMajor = new Unsigned32();
    public Unsigned32 uMinor = new Unsigned32();
    public Unsigned32 uRevision = new Unsigned32();
    public Unsigned32 uReserved = new Unsigned32();
}

public interface OpenH264 {
    public OpenH264Version WelsGetCodecVersion();
}

and finally trying it:

OpenH264 openH264 = LibraryLoader.create(OpenH264.class)
                    .load("openh264");
OpenH264Version version = openH264.WelsGetCodecVersion();

However, the returned version has wrong values (and they are different on each invocation).
The lib was x64 running on Windows 10 x64.
I could load the same lib with JNI+JavaCpp and the return values were correct.
What am I missing?

0

There are 0 best solutions below