我的java代码中确实有一个结构对象。但是使用JNAerator生成的Jar需要Structure.ByReference作为数据类型。在jna或代码片段中是否有将Structure对象转换为Structure.ByReference对象的方法?
发布于 2014-10-10 23:36:21
通常,在传递参数时不需要显式指定Structure.ByReference。如果它是一个参数,您可以从签名中删除.ByReference,这样它就可以正常工作了。
如果它是结构中的一个字段,那么JNA将Structure解释为值,在这种情况下,您需要显式地提供.ByReference。
这是一种方法。
class MyStructure extends Structure {
class ByReference extends MyStructure implements Structure.ByReference {
public ByReference() { }
public Byreference(Pointer p) { super(p); read(); }
}
public MyStructure() { }
public MyStructure(Pointer p) { super(p); read(); }
}
MyStructure s;
// ...
MyStructure.ByReference ref = new MyStructure.ByReference(s.getPointer());https://stackoverflow.com/questions/26288659
复制相似问题