// example struct: (sequential layout = just like C, the struct is just a memory-area with names...) [StructLayout(LayoutKind.Sequential)] struct HARDWAREINPUT { public uint uMsg; public ushort wParamL; public ushort wParamH; } // example union: (explicit lets you give each field an offset, careful though, it's not as simple as it seems) [StructLayout(LayoutKind.Explicit, Size = 28)] struct INPUT { [FieldOffset(0)] public InputSource type; [FieldOffset(4)] public MOUSEINPUT mi; [FieldOffset(4)] public KEYBDINPUT ki; [FieldOffset(4)] public HARDWAREINPUT hi; } // example, how-to-use: [StructLayout(LayoutKind.Sequential)] public struct LPRECT { public long left; public long top; public long right; public long bottom; } [DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr hWnd, ref LPRECT lpRect);