I am using custom types in the callback method and always get an empty value. What could be the problem?
C code in dll(i have .h file for this dll):
typedef union
{
char caStruct[16384];
struct
{
// Header
int iCode;
int iID;
int iResult;
int iInfo; // Bits 0-3 = 1: data structure TVehicleData, 2: TVehicleDataXL, 8: tCalResults
int iNum; // number of data sets
int iMask; // mask with participating sensors, if available
int iaReserve[10];
// "Payload"
char caData[];
};
} tResponse;
//callback function
DLL_PROC int __stdcall vwacom_ResultCallback( void (__stdcall *Results)( tResponse Response ) ); // 0
My java code:
Structure transformation:
@Structure.FieldOrder({"uResp"})
public class TResponse extends Structure {
public static class ByReference extends TResponse implements Structure.ByReference { }
public static class ByValue extends TResponse implements Structure.ByValue { }
public UnionResp uResp;
public static class UnionResp extends Union{
public static class ByReference extends TResponseU implements Union.ByReference { }
public static class ByValue extends TResponseU implements Union.ByValue { }
public String caStruct; //char[0x4000]
public StructResp sResp;
}
@Structure.FieldOrder({"iID","iCode","iResult","iInfo","iNum","iMask","iaReserve","caData"})
public static class StructResp extends Structure{
public static class ByReference extends TResponseS implements Structure.ByReference { }
public static class ByValue extends TResponseS implements Structure.ByValue { }
// Header
public int iID;
public int iCode;
public int iResult;
public int iInfo; // Bits 0-3 = 1: data structure TVehicleData, 2: TVehicleDataXL, 8: tCalResults
public int iNum; // number of data sets
public int iMask; // mask with participating sensors, if available
public int[] iaReserve = new int[10];
// "Payload"
public String caData; //char[]
}
}
dll interface:
public interface JNAVIsiWheAi extends Library {
JNAVIsiWheAi INSTANCE = (JNAVIsiWheAi) Native.load("C:\\CWM\\JNAVIsiWheAi.dll", JNAVIsiWheAi.class);
//vwacom_ResultCallback( void (__stdcall *Results)( tResponse Response ) );
interface Results extends Callback{
void invoke(TResponse tRes);
}
int vwacom_ResultCallback(Results results);
}
Use callback:
public void resultCallback() {
JNAVIsiWheAi.Results results = new JNAVIsiWheAi.Results() {
@Override
public void invoke(TResponse tRes) {
/*just many sout imformation */
}
};
jnavIsiWheAi.vwacom_ResultCallback(results);
}
I don't get errors, but when outputting values, they are always empty.
My example console output looks like this:
- caStruct = null; iID=0; iCode=0; iResult=0; iInfo=0; iNum=0; iMask=0 iaReserve =[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; caData=null