Hello,
I have 2 structs:
public struct th_skimFacadeSolution{
public transportTypes sType;
public th_VMPObjGeneric[] allparts;
public th_skimFacadeSolution(th_VMPObjGeneric[] allcomps, bool velocity) {
allparts = allcomps;
sType = velocity ? transportTypes.skimVelocity : transportTypes.skimPositions;
}
}
public struct th_VMPObjGeneric {
public string sName;
public Vector3 sPos;
public Vector3 sRot;
public th_VMPObjGeneric(string n,Vector3 p,Vector3 r) {
sName = n;
sPos = p;
sRot = r;
}
}
I then have a converter class for the first to byte[ ] and back:
public static byte[] skimSolutionConverter(th_skimFacadeSolution str) {
int size = Marshal.SizeOf(str);
byte[] arr = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(str,ptr,true);
Marshal.Copy(ptr,arr,0,size);
Marshal.FreeHGlobal(ptr);
arr = addByteToArray(arr,(byte)str.sType);
return arr;
}
public static th_skimFacadeSolution skimSolutionConverter(byte[] bytes) {
bytes = removeFirstByte(bytes);
th_skimFacadeSolution str = new th_skimFacadeSolution();
int size = Marshal.SizeOf(str);
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(bytes,0,ptr,size);
str = (th_skimFacadeSolution)Marshal.PtrToStructure(ptr,str.GetType());
Marshal.FreeHGlobal(ptr);
return str;
}
I then get this error on receiving the bytes and converting:
MarshalDirectiveException: Structure field of type th_VMPObjGeneric[] can't be marshalled as LPArray (wrapper unknown) th_skimFacadeSolution:PtrToStructure (intptr,object) }
I get that Marshalling cant deal with the nested struct array inside the first struct as it is currently written. I have tried to go over the documents, but this is well outside my wheelhouse.
Is this a simple fix, or does it involve a lot more research on my behalf?
Thanks very much,
Ryan