I have googled for a long time, and nothing helps.
EDIT: This is the code after implementing technomage's advice.
Example struct C++ code:
typedef struct _SOMESTRUCT{
const char* String1;
const char* String2;
} SOMESTRUCT, *LPSOMESTRUCT;
Example C++ function that "fills up" the struct with data:
int GetSomeStruct(_SOMESTRUCT somes);
Translation of struct to java:
public class SomeStruct extends Structure{
public String String1;
public String String2;
public class ByValue extends SomeStruct implements Structure.ByValue{}
public SomeStruct(Pointer p){ //constructors of struct
super(p);
read();
}
public SomeStruct(){
super();
read();
}
}
Translation of function to java method:
int GetSomeStruct(SomeStruct.ByValue structref);
How I execute the code from main Java app:
EnclosingClass.SomeStruct sstruct = enclosingInstance.new SomeStruct();
EnclosingClass.SomeStruc.ByValue sstructval = sstruct.new ByValue();
enclosingInstanceofClasswithTranslatedCfunctions.GetSomeStruct(sstructref);
Assumptions:
- I have correctly executed Native.loadLibrary before attempting to use the function. (simpler functions that return ints work fine as does a callback function for receiving event notifications)
- The java translations are both in separate files (as in the c code) nested in public classes that extend JNA library.
- The int that is returned by GetSomeStruct is zero if everything executes well on the c side. I keep getting zero.