I know that you can use code like this to marshal a structure into a byte array:
public static byte[] StructureToByteArray(object obj)
{
int len = Marshal.SizeOf(obj);
byte[] arr = new byte[len];
IntPtr ptr = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(obj, ptr, true);
Marshal.Copy(ptr, arr, 0, len);
Marshal.FreeHGlobal(ptr);
return arr;
}
But how do you marshal a structure into an array containing 16 bit words instead of bytes?
public static UInt16[] StructureToUInt16Array(object obj)
{
// What to do?
}