diff --git a/PInvoke/DwmApi/DwmApi.cs b/PInvoke/DwmApi/DwmApi.cs index 99a2781e..22a9577e 100644 --- a/PInvoke/DwmApi/DwmApi.cs +++ b/PInvoke/DwmApi/DwmApi.cs @@ -599,7 +599,7 @@ public static partial class DwmApi /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [DllImport(Lib.DwmApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("dwmapi.h")] - public static extern HRESULT DwmGetCompositionTimingInfo(HWND hwnd, ref DWM_TIMING_INFO dwAttribute); + public static extern HRESULT DwmGetCompositionTimingInfo([Optional] HWND hwnd, ref DWM_TIMING_INFO dwAttribute); /// Retrieves transport attributes. /// @@ -827,12 +827,12 @@ public static partial class DwmApi /// /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PInvokeData("dwmapi.h")] - public static HRESULT DwmSetWindowAttribute(HWND hwnd, DWMWINDOWATTRIBUTE dwAttribute, [In] T pvAttribute) + public static HRESULT DwmSetWindowAttribute(HWND hwnd, DWMWINDOWATTRIBUTE dwAttribute, [In] T? pvAttribute) { if (pvAttribute == null || !CorrespondingTypeAttribute.CanSet(dwAttribute, typeof(T))) throw new ArgumentException(); var attr = pvAttribute is bool ? Convert.ToUInt32(pvAttribute) : (pvAttribute.GetType().IsEnum ? Convert.ChangeType(pvAttribute, Enum.GetUnderlyingType(pvAttribute.GetType())) : pvAttribute); - using (var p = new PinnedObject(attr)) - return DwmSetWindowAttribute(hwnd, dwAttribute, p, Marshal.SizeOf(attr)); + using var p = new PinnedObject(attr); + return DwmSetWindowAttribute(hwnd, dwAttribute, p, Marshal.SizeOf(attr)); } /// @@ -1236,7 +1236,7 @@ public static partial class DwmApi { int RotateLeft(int value, int nBits) { - nBits = nBits % 0x20; + nBits %= 0x20; return (value << nBits) | (value >> (0x20 - nBits)); } return cxLeftWidth ^ RotateLeft(cyTopHeight, 8) ^ RotateLeft(cxRightWidth, 0x10) ^ RotateLeft(cyBottomHeight, 0x18); diff --git a/UnitTests/PInvoke/DwmApi/DwmApi.csproj b/UnitTests/PInvoke/DwmApi/DwmApi.csproj index 5b0bfb22..efe28f61 100644 --- a/UnitTests/PInvoke/DwmApi/DwmApi.csproj +++ b/UnitTests/PInvoke/DwmApi/DwmApi.csproj @@ -1,6 +1,8 @@  UnitTest.PInvoke.DwmApi + $(TargetFramework)-windows + true diff --git a/UnitTests/PInvoke/DwmApi/DwmApiTests.cs b/UnitTests/PInvoke/DwmApi/DwmApiTests.cs index 67fa486a..d2d002f0 100644 --- a/UnitTests/PInvoke/DwmApi/DwmApiTests.cs +++ b/UnitTests/PInvoke/DwmApi/DwmApiTests.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using System.Drawing; using System.Threading; +using System.Windows.Forms; using static Vanara.PInvoke.DwmApi; namespace Vanara.PInvoke.Tests;