diff --git a/src/Common/src/NativeMethods.cs b/src/Common/src/NativeMethods.cs index b4a24211b69..afcaad845ec 100644 --- a/src/Common/src/NativeMethods.cs +++ b/src/Common/src/NativeMethods.cs @@ -2007,12 +2007,11 @@ public PICTDESCemf(System.Drawing.Imaging.Metafile metafile) } } - [StructLayout(LayoutKind.Sequential)] - public class USEROBJECTFLAGS + public struct USEROBJECTFLAGS { - public int fInherit = 0; - public int fReserved = 0; - public int dwFlags = 0; + public int fInherit; + public int fReserved; + public int dwFlags; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] diff --git a/src/Common/src/UnsafeNativeMethods.cs b/src/Common/src/UnsafeNativeMethods.cs index 53a95e4b1c8..8a27a07ea94 100644 --- a/src/Common/src/UnsafeNativeMethods.cs +++ b/src/Common/src/UnsafeNativeMethods.cs @@ -1104,7 +1104,7 @@ public static bool TrySystemParametersInfoForDpi(int nAction, int nParam, [In, O public static extern IntPtr GetProcessWindowStation(); [DllImport(ExternDll.User32, SetLastError = true)] - public static extern bool GetUserObjectInformation(HandleRef hObj, int nIndex, [MarshalAs(UnmanagedType.LPStruct)] NativeMethods.USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded); + public static extern bool GetUserObjectInformation(HandleRef hObj, int nIndex, ref NativeMethods.USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern int ClientToScreen(HandleRef hWnd, [In, Out] NativeMethods.POINT pt); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs b/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs index 82470af3312..b6451c345f7 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs @@ -795,7 +795,7 @@ public static string ComputerName /// Gets a value indicating whether the current process is running in user /// interactive mode. /// - public static bool UserInteractive + public unsafe static bool UserInteractive { get { @@ -807,7 +807,7 @@ public static bool UserInteractive int lengthNeeded = 0; NativeMethods.USEROBJECTFLAGS flags = new NativeMethods.USEROBJECTFLAGS(); - if (UnsafeNativeMethods.GetUserObjectInformation(new HandleRef(null, hwinsta), NativeMethods.UOI_FLAGS, flags, Marshal.SizeOf(flags), ref lengthNeeded)) + if (UnsafeNativeMethods.GetUserObjectInformation(new HandleRef(null, hwinsta), NativeMethods.UOI_FLAGS, ref flags, sizeof(NativeMethods.USEROBJECTFLAGS), ref lengthNeeded)) { if ((flags.dwFlags & NativeMethods.WSF_VISIBLE) == 0) {