From 891f9bd95a461993e9e9c4ce7362b57a9680498e Mon Sep 17 00:00:00 2001 From: Jeremy Kuhne Date: Wed, 20 Nov 2024 14:57:52 -0800 Subject: [PATCH] Update CsWin32 version --- src/thirtytwo/DeviceContext.cs | 2 +- src/thirtytwo/Wdk/Interop.NtQueryKey.cs | 2 +- src/thirtytwo/Win32/Foundation/HANDLE.cs | 2 +- src/thirtytwo/Win32/Foundation/LRESULT.cs | 10 ++++++++++ src/thirtytwo/Win32/Foundation/WPARAM.cs | 6 +++--- src/thirtytwo/Win32/Graphics/Gdi/HBRUSH.cs | 2 +- src/thirtytwo/Win32/Graphics/Gdi/HDC.cs | 4 +--- src/thirtytwo/Win32/Graphics/Gdi/HGDIOBJ.cs | 10 +++++----- src/thirtytwo/Win32/Graphics/Gdi/HPEN.cs | 2 +- src/thirtytwo/Win32/Graphics/Gdi/HRGN.cs | 2 +- src/thirtytwo/Win32/System/Registry/HKEY.cs | 6 +++--- src/thirtytwo/Win32/System/Registry/Registry.cs | 1 + src/thirtytwo/Win32/UI/HiDpi/DPI_AWARENESS_CONTEXT.cs | 9 --------- src/thirtytwo/thirtytwo.csproj | 8 ++++++-- 14 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 src/thirtytwo/Win32/Foundation/LRESULT.cs delete mode 100644 src/thirtytwo/Win32/UI/HiDpi/DPI_AWARENESS_CONTEXT.cs diff --git a/src/thirtytwo/DeviceContext.cs b/src/thirtytwo/DeviceContext.cs index 15fdad8..82de352 100644 --- a/src/thirtytwo/DeviceContext.cs +++ b/src/thirtytwo/DeviceContext.cs @@ -143,7 +143,7 @@ public unsafe void Dispose() } public static implicit operator HDC(DeviceContext context) => context.Handle; - public static unsafe explicit operator DeviceContext(WPARAM wparam) => Create(new(new(wparam))); + public static unsafe explicit operator DeviceContext(WPARAM wparam) => Create(new((nint)wparam)); [Flags] private enum ContextState diff --git a/src/thirtytwo/Wdk/Interop.NtQueryKey.cs b/src/thirtytwo/Wdk/Interop.NtQueryKey.cs index a462c0a..2efa32d 100644 --- a/src/thirtytwo/Wdk/Interop.NtQueryKey.cs +++ b/src/thirtytwo/Wdk/Interop.NtQueryKey.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Runtime.InteropServices; -using Windows.Wdk.System.SystemServices; +using Windows.Wdk.System.Registry; using Windows.Win32.System.Registry; namespace Windows.Wdk; diff --git a/src/thirtytwo/Win32/Foundation/HANDLE.cs b/src/thirtytwo/Win32/Foundation/HANDLE.cs index f4c4758..5fb2865 100644 --- a/src/thirtytwo/Win32/Foundation/HANDLE.cs +++ b/src/thirtytwo/Win32/Foundation/HANDLE.cs @@ -10,7 +10,7 @@ namespace Windows.Win32.Foundation; { public unsafe void Dispose() { - if (Value != 0 && Value != -1) + if ((nint)Value != 0 && (nint)Value != -1) { Interop.CloseHandle(this).ThrowLastErrorIfFalse(); } diff --git a/src/thirtytwo/Win32/Foundation/LRESULT.cs b/src/thirtytwo/Win32/Foundation/LRESULT.cs new file mode 100644 index 0000000..72a3a11 --- /dev/null +++ b/src/thirtytwo/Win32/Foundation/LRESULT.cs @@ -0,0 +1,10 @@ +// Copyright (c) Jeremy W. Kuhne. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Windows.Win32.Foundation; + +public unsafe readonly partial struct LRESULT +{ + public static explicit operator void*(LRESULT value) => (void*)value.Value; + public static explicit operator LRESULT(void* value) => new((nint)value); +} \ No newline at end of file diff --git a/src/thirtytwo/Win32/Foundation/WPARAM.cs b/src/thirtytwo/Win32/Foundation/WPARAM.cs index 40717e6..bf7397f 100644 --- a/src/thirtytwo/Win32/Foundation/WPARAM.cs +++ b/src/thirtytwo/Win32/Foundation/WPARAM.cs @@ -5,10 +5,10 @@ namespace Windows.Win32.Foundation; -public readonly partial struct WPARAM +public unsafe readonly partial struct WPARAM { - public static unsafe implicit operator void*(WPARAM value) => (void*)value.Value; - public static unsafe implicit operator WPARAM(void* value) => new((nuint)value); + public static implicit operator void*(WPARAM value) => (void*)value.Value; + public static implicit operator WPARAM(void* value) => new((nuint)value); public static explicit operator HWND(WPARAM value) => (HWND)(nint)value.Value; public static explicit operator WPARAM(HWND value) => new((nuint)value.Value); diff --git a/src/thirtytwo/Win32/Graphics/Gdi/HBRUSH.cs b/src/thirtytwo/Win32/Graphics/Gdi/HBRUSH.cs index 614c828..5118988 100644 --- a/src/thirtytwo/Win32/Graphics/Gdi/HBRUSH.cs +++ b/src/thirtytwo/Win32/Graphics/Gdi/HBRUSH.cs @@ -24,7 +24,7 @@ public static explicit operator HBRUSH(HGDIOBJ handle) public void Dispose() { - if (Value != 0 && Value != -1) + if ((nint)Value != 0 && (nint)Value != -1) { Interop.DeleteObject(this); Unsafe.AsRef(in this) = default; diff --git a/src/thirtytwo/Win32/Graphics/Gdi/HDC.cs b/src/thirtytwo/Win32/Graphics/Gdi/HDC.cs index 4554079..7f57d38 100644 --- a/src/thirtytwo/Win32/Graphics/Gdi/HDC.cs +++ b/src/thirtytwo/Win32/Graphics/Gdi/HDC.cs @@ -5,13 +5,11 @@ namespace Windows.Win32.Graphics.Gdi; -public partial struct HDC : IHandle +public unsafe partial struct HDC : IHandle { HDC IHandle.Handle => this; object? IHandle.Wrapper => null; - public bool IsNull => Value == 0; - public static explicit operator HDC(HGDIOBJ handle) { Debug.Assert(handle.IsNull || (OBJ_TYPE)Interop.GetObjectType(handle) == OBJ_TYPE.OBJ_DC); diff --git a/src/thirtytwo/Win32/Graphics/Gdi/HGDIOBJ.cs b/src/thirtytwo/Win32/Graphics/Gdi/HGDIOBJ.cs index 6e9aad7..8a9390f 100644 --- a/src/thirtytwo/Win32/Graphics/Gdi/HGDIOBJ.cs +++ b/src/thirtytwo/Win32/Graphics/Gdi/HGDIOBJ.cs @@ -7,9 +7,9 @@ public unsafe partial struct HGDIOBJ { public OBJ_TYPE GetObjectType() => (OBJ_TYPE)Interop.GetObjectType(this); - public static implicit operator HGDIOBJ(StockFont font) => new(Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)font)); - public static implicit operator HGDIOBJ(StockBrush brush) => new(Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)brush)); - public static implicit operator HGDIOBJ(SystemColor color) => new(Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)color)); - public static implicit operator HGDIOBJ(StockPen pen) => new(Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)pen)); - public static implicit operator HGDIOBJ(GET_STOCK_OBJECT_FLAGS stockObject) => new(Interop.GetStockObject(stockObject)); + public static implicit operator HGDIOBJ(StockFont font) => new((nint)Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)font)); + public static implicit operator HGDIOBJ(StockBrush brush) => new((nint)Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)brush)); + public static implicit operator HGDIOBJ(SystemColor color) => new((nint)Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)color)); + public static implicit operator HGDIOBJ(StockPen pen) => new((nint)Interop.GetStockObject((GET_STOCK_OBJECT_FLAGS)pen)); + public static implicit operator HGDIOBJ(GET_STOCK_OBJECT_FLAGS stockObject) => new((nint)Interop.GetStockObject(stockObject)); } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Gdi/HPEN.cs b/src/thirtytwo/Win32/Graphics/Gdi/HPEN.cs index 6c80354..612c5af 100644 --- a/src/thirtytwo/Win32/Graphics/Gdi/HPEN.cs +++ b/src/thirtytwo/Win32/Graphics/Gdi/HPEN.cs @@ -21,7 +21,7 @@ public static explicit operator HPEN(HGDIOBJ handle) public void Dispose() { - if (Value != 0 && Value != -1) + if ((nint)Value != 0 && (nint)Value != -1) { Interop.DeleteObject(this); Unsafe.AsRef(in this) = default; diff --git a/src/thirtytwo/Win32/Graphics/Gdi/HRGN.cs b/src/thirtytwo/Win32/Graphics/Gdi/HRGN.cs index b486336..abc96fa 100644 --- a/src/thirtytwo/Win32/Graphics/Gdi/HRGN.cs +++ b/src/thirtytwo/Win32/Graphics/Gdi/HRGN.cs @@ -26,7 +26,7 @@ public void Dispose() /// /// Special sent during WM_NCPAINT to indicate the entire window. /// - public static HRGN Full { get; } = (HRGN)1; + public static HRGN Full { get; } = (HRGN)(nint)1; /// /// Is special value. diff --git a/src/thirtytwo/Win32/System/Registry/HKEY.cs b/src/thirtytwo/Win32/System/Registry/HKEY.cs index c9edbfa..f2f8198 100644 --- a/src/thirtytwo/Win32/System/Registry/HKEY.cs +++ b/src/thirtytwo/Win32/System/Registry/HKEY.cs @@ -5,7 +5,7 @@ namespace Windows.Win32.System.Registry; -public partial struct HKEY : IDisposable +public unsafe partial struct HKEY : IDisposable { private const uint REMOTE_HANDLE_TAG = 0x00000001; private const uint REG_CLASSES_SPECIAL_TAG = 0x00000002; @@ -16,13 +16,13 @@ public bool IsPerfKey() /// /// Returns true if the key is from the local machine. /// - public bool IsLocalKey => (Value & REMOTE_HANDLE_TAG) == 0; + public bool IsLocalKey => ((nuint)Value & REMOTE_HANDLE_TAG) == 0; /// /// Returns true if the key is special (notably in , where /// it might be redirected to per user settings). /// - public bool IsSpecialKey => (Value & REG_CLASSES_SPECIAL_TAG) != 0; + public bool IsSpecialKey => ((nuint)Value & REG_CLASSES_SPECIAL_TAG) != 0; public void Dispose() { diff --git a/src/thirtytwo/Win32/System/Registry/Registry.cs b/src/thirtytwo/Win32/System/Registry/Registry.cs index 6536a9e..93314cc 100644 --- a/src/thirtytwo/Win32/System/Registry/Registry.cs +++ b/src/thirtytwo/Win32/System/Registry/Registry.cs @@ -4,6 +4,7 @@ using System.Buffers.Binary; using System.Runtime.InteropServices; using Windows.Support; +using Windows.Wdk.System.Registry; using Windows.Wdk.System.SystemServices; namespace Windows.Win32.System.Registry; diff --git a/src/thirtytwo/Win32/UI/HiDpi/DPI_AWARENESS_CONTEXT.cs b/src/thirtytwo/Win32/UI/HiDpi/DPI_AWARENESS_CONTEXT.cs deleted file mode 100644 index 0bc7e85..0000000 --- a/src/thirtytwo/Win32/UI/HiDpi/DPI_AWARENESS_CONTEXT.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Jeremy W. Kuhne. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Windows.Win32.UI.HiDpi; - -public partial struct DPI_AWARENESS_CONTEXT -{ - public bool IsNull => Value == 0; -} \ No newline at end of file diff --git a/src/thirtytwo/thirtytwo.csproj b/src/thirtytwo/thirtytwo.csproj index 7cecf0f..0a82809 100644 --- a/src/thirtytwo/thirtytwo.csproj +++ b/src/thirtytwo/thirtytwo.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -21,7 +21,11 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + +