I do have a object of Structure in my java code. But the Jar generated using JNAerator expects Structure.ByReference as a data type. Is there any method in jna or code snippet to convert Structure object into Structure.ByReference object?
Generally, you don't need to explicitly specify Structure.ByReference
when passing parameters. If it's a parameter, you can drop the .ByReference
from the signature and it'll work just fine.
If it's a field within a structure, then JNA interprets Structure
as by value, in which case you would need to provide the .ByReference
explicitly.
This is one way to do it.
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());
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.