我正在尝试使用JNR使用Java代码中的openh264本机库。我正在调用的函数在openh264的C头文件中定义,以按值返回简单的结构:
typedef struct _tagVersion {
unsigned int uMajor;
unsigned int uMinor;
unsigned int uRevision;
unsigned int uReserved;
} OpenH264Version;
OpenH264Version WelsGetCodecVersion (void);
我写了以下Java对应文章:
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();
}
最后尝试:
OpenH264 openH264 = LibraryLoader.create(OpenH264.class)
.load("openh264");
OpenH264Version version = openH264.WelsGetCodecVersion();
但是,返回的版本具有错误的值(并且每次调用它们都不同)。
该库是在Windows 10 x64上运行的x64。
我可以使用JNI + JavaCpp加载相同的库,并且返回值正确。
我想念什么?