public static void WriteValue(this IntPtr baseAddr, ref int offset, ItemType type, object value) { switch (type) { case ItemType.Int8: case ItemType.UInt8: Marshal.WriteByte(baseAddr, offset, Convert.ToByte(value, CultureInfo.InvariantCulture)); // (byte)value); break; case ItemType.Bool: case ItemType.Int16: case ItemType.UInt16: Marshal.WriteInt16(baseAddr, offset, Convert.ToInt16(value, CultureInfo.InvariantCulture)); //(short)value); break; case ItemType.UInt32: case ItemType.Int32: Marshal.WriteInt32(baseAddr, offset, Convert.ToInt32(value, CultureInfo.InvariantCulture)); //(int)value); break; case ItemType.Fix32: TW_FIX32 f32 = (TW_FIX32)value; WriteFix32(baseAddr, ref offset, f32); return; // no need to update offset for this case ItemType.Frame: TW_FRAME frame = (TW_FRAME)value; WriteFix32(baseAddr, ref offset, frame._left); WriteFix32(baseAddr, ref offset, frame._top); WriteFix32(baseAddr, ref offset, frame._right); WriteFix32(baseAddr, ref offset, frame._bottom); return; // no need to update offset for this //case ItemType.String1024: // WriteString(baseAddr, offset, value as string, 1024); // break; case ItemType.String128: WriteString(baseAddr, offset, (string)value, 128); break; case ItemType.String255: WriteString(baseAddr, offset, (string)value, 255); break; case ItemType.String32: WriteString(baseAddr, offset, (string)value, 32); break; case ItemType.String64: WriteString(baseAddr, offset, (string)value, 64); break; //case ItemType.Unicode512: // WriteUString(baseAddr, offset, value as string, 512); // break; } offset += type.GetSize(); }
private static void WriteFix32(IntPtr baseAddr, ref int offset, TW_FIX32 f32) { Marshal.WriteInt16(baseAddr, offset, f32.Whole); if (f32.Fraction > Int16.MaxValue) { Marshal.WriteInt16(baseAddr, offset + 2, (Int16)(f32.Fraction - 32768)); } else { Marshal.WriteInt16(baseAddr, offset + 2, (Int16)f32.Fraction); } offset += _sizes[ItemType.Fix32]; }