Browse Source

Switch from DllImport to LibraryImport source generator

pull/3212/head
Christoph Wille 1 year ago
parent
commit
bc8decc748
  1. 13
      ILSpy/NativeMethods.cs

13
ILSpy/NativeMethods.cs

@ -21,16 +21,19 @@ using System.Runtime.InteropServices;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
{ {
static class NativeMethods // Uses https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke-source-generation
internal static partial class NativeMethods
{ {
[DllImport("dwmapi.dll", PreserveSig = true)] const int S_OK = 0;
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DwmWindowAttribute attr, ref int attrValue, int attrSize);
[LibraryImport("dwmapi.dll", EntryPoint = "DwmSetWindowAttribute")]
internal static partial int DwmSetWindowAttribute(IntPtr hwnd, DwmWindowAttribute attr, ref int attrValue, int attrSize);
public static bool UseImmersiveDarkMode(IntPtr hWnd, bool enable) public static bool UseImmersiveDarkMode(IntPtr hWnd, bool enable)
{ {
int darkMode = enable ? 1 : 0; int darkMode = enable ? 1 : 0;
int hr = DwmSetWindowAttribute(hWnd, DwmWindowAttribute.UseImmersiveDarkMode, ref darkMode, sizeof(int)); int hResult = DwmSetWindowAttribute(hWnd, DwmWindowAttribute.UseImmersiveDarkMode, ref darkMode, sizeof(int));
return hr >= 0; return hResult > S_OK;
} }
} }

Loading…
Cancel
Save