i have to define a struct works with unsafe code, so i have to set the FieldOffset values of every fields. But i cannot define size of pointer. Here is the code :
[StructLayout(LayoutKind.Explicit)]
public struct SomeStructO
{
public SomeStructO(int theNumber)
{
TheNumber = theNumber;
Coordinates = PointF.Empty;
SomeNumbers = null;
}
[FieldOffset(0)]
public PointF Coordinates;
[FieldOffset(sizeof(float) * 2)]
public int[] SomeNumbers;
[FieldOffset(sizeof(float) * 2 + IntPtr.Size)]
public int TheNumber;
}
gives an error because IntPtr.Size is not a constant expression and ofcourse this one doesnt compile either:
Marshal.SizeOf(typeof(IntPtr))
when it comes down to question title, it is more how i can set specific "32bit 64bit compile" pointer data size in FieldOffset definition.
Edit: and also i can not put the "public int[] SomeNumbers;" field at the end of the struct, because i have 2 different arrays in my struct.. like "public int[] SomeOtherNumbers;"