diff --git a/src/Common/src/Interop/Windows/User32/Interop.GetUserObjectInformation.cs b/src/Common/src/Interop/Windows/User32/Interop.GetUserObjectInformation.cs index 82df65c8f120..9afdf0ca6ae4 100644 --- a/src/Common/src/Interop/Windows/User32/Interop.GetUserObjectInformation.cs +++ b/src/Common/src/Interop/Windows/User32/Interop.GetUserObjectInformation.cs @@ -10,6 +10,6 @@ internal partial class Interop internal partial class User32 { [DllImport(Libraries.User32, SetLastError=true, CharSet = CharSet.Unicode, ExactSpelling = true)] - public static extern bool GetUserObjectInformationW(IntPtr hObj, int nIndex, [MarshalAs(UnmanagedType.LPStruct)] USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded); + public static extern bool GetUserObjectInformationW(IntPtr hObj, int nIndex, ref USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded); } } diff --git a/src/Common/src/Interop/Windows/User32/Interop.USEROBJECTFLAGS.cs b/src/Common/src/Interop/Windows/User32/Interop.USEROBJECTFLAGS.cs index 38f4cc3e97fe..f52e0cdd3150 100644 --- a/src/Common/src/Interop/Windows/User32/Interop.USEROBJECTFLAGS.cs +++ b/src/Common/src/Interop/Windows/User32/Interop.USEROBJECTFLAGS.cs @@ -8,11 +8,10 @@ internal partial class Interop { internal partial class User32 { - [StructLayout(LayoutKind.Sequential)] - internal class USEROBJECTFLAGS { - public int fInherit = 0; - public int fReserved = 0; - public int dwFlags = 0; + internal struct USEROBJECTFLAGS { + public int fInherit; + public int fReserved; + public int dwFlags; } } } diff --git a/src/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs b/src/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs index 4ab55405805a..ca7ba8d1e0af 100644 --- a/src/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs +++ b/src/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs @@ -90,7 +90,7 @@ private SystemEvents() [SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] private static volatile IntPtr s_processWinStation = IntPtr.Zero; private static volatile bool s_isUserInteractive = false; - private static bool UserInteractive + private unsafe static bool UserInteractive { get { @@ -106,7 +106,7 @@ private static bool UserInteractive int lengthNeeded = 0; Interop.User32.USEROBJECTFLAGS flags = new Interop.User32.USEROBJECTFLAGS(); - if (Interop.User32.GetUserObjectInformationW(hwinsta, Interop.User32.UOI_FLAGS, flags, Marshal.SizeOf(flags), ref lengthNeeded)) + if (Interop.User32.GetUserObjectInformationW(hwinsta, Interop.User32.UOI_FLAGS, ref flags, sizeof(Interop.User32.USEROBJECTFLAGS), ref lengthNeeded)) { if ((flags.dwFlags & Interop.User32.WSF_VISIBLE) == 0) {