public NativeImport.NativeStructs.RawInput GetRawInputData(IntPtr lParam) { uint dwSize = 0; NativeImport.GetRawInputData( lParam, RID_INPUT, IntPtr.Zero, ref dwSize, (uint)Marshal.SizeOf(typeof(NativeImport.NativeStructs.RawInputHeader)) ); IntPtr buffer = Marshal.AllocHGlobal((int)dwSize); NativeImport.GetRawInputData( lParam, RID_INPUT, buffer, ref dwSize, (uint)Marshal.SizeOf(typeof(NativeImport.NativeStructs.RawInputHeader)) ); NativeImport.NativeStructs.RawInput raw = (NativeImport.NativeStructs.RawInput)Marshal.PtrToStructure(buffer, typeof(NativeImport.NativeStructs.RawInput)); Marshal.FreeHGlobal(buffer); return(raw); }