manually pinvoke from win32metadata

This commit is contained in:
Lightczx
2024-01-25 11:01:45 +08:00
parent 45248d75e1
commit d686debbfb
124 changed files with 6265 additions and 436 deletions

View File

@@ -1,11 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/CsWin32/main/src/Microsoft.Windows.CsWin32/settings.schema.json",
"allowMarshaling": true,
"useSafeHandles": false,
"comInterop": {
"preserveSigMethods": [
"IFileOpenDialog.Show",
"IFileSaveDialog.Show"
]
}
}

View File

@@ -1,117 +0,0 @@
// ADVAPI32
RegCloseKey
RegOpenKeyExW
RegNotifyChangeKeyValue
// COMCTL32
DefSubclassProc
RemoveWindowSubclass
SetWindowSubclass
// DWMAPI
DwmSetWindowAttribute
// GDI32
GetDeviceCaps
// KERNEL32
AllocConsole
CloseHandle
CreateEventW
CreateRemoteThread
FreeConsole
GetConsoleMode
GetModuleHandleW
GetProcAddress
GetStdHandle
K32EnumProcessModules
K32GetModuleBaseNameW
K32GetModuleInformation
ReadProcessMemory
SetConsoleMode
SetConsoleTitle
SetEvent
VirtualAlloc
VirtualAllocEx
VirtualFree
VirtualFreeEx
WaitForSingleObject
WriteProcessMemory
// OLE32
CoCreateInstance
CoWaitForMultipleObjects
// SHELL32
SHCreateItemFromParsingName
// USER32
AttachThreadInput
FindWindowExW
GetCursorPos
GetDC
GetDpiForWindow
GetForegroundWindow
GetWindowLongPtrW
GetWindowPlacement
GetWindowThreadProcessId
ReleaseDC
RegisterHotKey
SendInput
SetForegroundWindow
SetWindowLongPtrW
UnregisterHotKey
// COM
FileOpenDialog
FileSaveDialog
IFileOpenDialog
IFileSaveDialog
IPersistFile
IShellLinkDataList
IShellLinkW
ShellLink
SHELL_LINK_DATA_FLAGS
// WinRT
IMemoryBufferByteAccess
// Macro
HRESULT_FROM_WIN32
// Const value
INFINITE
MAX_PATH
WM_ERASEBKGND
WM_GETMINMAXINFO
WM_HOTKEY
WM_NCRBUTTONDOWN
WM_NCRBUTTONUP
WM_NULL
// HKEY
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
// HRESULT
E_FAIL
RPC_E_WRONG_THREAD
// System.Com
CWMO_FLAGS
// System.Registry
REG_NOTIFY_FILTER
// System.Threading
LPTHREAD_START_ROUTINE
// UI.Shell
SLGP_FLAGS
// UI.WindowsAndMessaging
MINMAXINFO
WINDOW_EX_STYLE

View File

@@ -1,17 +0,0 @@
using System;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
namespace Windows.Win32;
internal static partial class PInvoke
{
/// <inheritdoc cref="CoCreateInstance(Guid*, object, CLSCTX, Guid*, out object)"/>
internal static unsafe HRESULT CoCreateInstance<TClass, TInterface>(object? pUnkOuter, CLSCTX dwClsContext, out TInterface ppv)
where TInterface : class
{
HRESULT hr = CoCreateInstance(typeof(TClass).GUID, pUnkOuter, dwClsContext, typeof(TInterface).GUID, out object o);
ppv = (TInterface)o;
return hr;
}
}

View File

@@ -1,26 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<None Remove="NativeMethods.json" />
<None Remove="NativeMethods.txt" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="NativeMethods.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -1,24 +0,0 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.CompilerServices;
using Windows.Win32.UI.WindowsAndMessaging;
[assembly: InternalsVisibleTo("Snap.Hutao")]
namespace Snap.Hutao.Win32;
/// <summary>
/// 结构体封送
/// </summary>
internal static class StructMarshal
{
/// <summary>
/// 构造一个新的 <see cref="Windows.Win32.UI.WindowsAndMessaging.WINDOWPLACEMENT"/>
/// </summary>
/// <returns>新的实例</returns>
public static unsafe WINDOWPLACEMENT WINDOWPLACEMENT()
{
return new() { length = unchecked((uint)sizeof(WINDOWPLACEMENT)) };
}
}

View File

@@ -13,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.Test", "Snap.Hutao.Test\Snap.Hutao.Test.csproj", "{D691BA9F-904C-4229-87A5-E14F2EFF2F64}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.Win32", "Snap.Hutao.Win32\Snap.Hutao.Win32.csproj", "{0F7ABEB2-5107-4037-B9DC-84D288FB0801}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -67,32 +65,16 @@ Global
{D691BA9F-904C-4229-87A5-E14F2EFF2F64}.Release|x64.Build.0 = Release|Any CPU
{D691BA9F-904C-4229-87A5-E14F2EFF2F64}.Release|x86.ActiveCfg = Release|Any CPU
{D691BA9F-904C-4229-87A5-E14F2EFF2F64}.Release|x86.Build.0 = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|arm64.ActiveCfg = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|arm64.Build.0 = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|x64.ActiveCfg = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|x64.Build.0 = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|x86.ActiveCfg = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Debug|x86.Build.0 = Debug|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|Any CPU.Build.0 = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|arm64.ActiveCfg = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|arm64.Build.0 = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|x64.ActiveCfg = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|x64.Build.0 = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|x86.ActiveCfg = Release|Any CPU
{0F7ABEB2-5107-4037-B9DC-84D288FB0801}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_Rules = {"EnabledRules":["StringFormat","WhiteSpaceLead","WhiteSpaceTail","PunctuationLead"]}
RESX_ShowErrorsInErrorList = False
RESX_SortFileContentOnSave = True
SolutionGuid = {E4449B1C-0E6A-4D19-955E-1CA491656ABA}
RESX_NeutralResourcesLanguage = zh-CN
RESX_AutoApplyExistingTranslations = False
RESX_NeutralResourcesLanguage = zh-CN
SolutionGuid = {E4449B1C-0E6A-4D19-955E-1CA491656ABA}
RESX_SortFileContentOnSave = True
RESX_ShowErrorsInErrorList = False
RESX_Rules = {"EnabledRules":["StringFormat","WhiteSpaceLead","WhiteSpaceTail","PunctuationLead"]}
EndGlobalSection
EndGlobal

View File

@@ -50,7 +50,6 @@ public sealed partial class App : Application
{
// Load app resource
InitializeComponent();
activation = serviceProvider.GetRequiredService<IActivation>();
logger = serviceProvider.GetRequiredService<ILogger<App>>();
serviceProvider.GetRequiredService<ExceptionRecorder>().Record(this);

View File

@@ -1,10 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.System.WinRT;
using Windows.Foundation;
using Windows.Graphics.Imaging;
using Windows.Win32;
using Windows.Win32.System.WinRT;
using WinRT;
namespace Snap.Hutao.Control.Media;

View File

@@ -18,6 +18,7 @@ internal sealed partial class DynamicHttpProxy : IWebProxy, IDisposable
private IWebProxy innerProxy = default!;
[SuppressMessage("", "CA1810")]
static DynamicHttpProxy()
{
Type? systemProxyInfoType = typeof(System.Net.Http.SocketsHttpHandler).Assembly.GetType("System.Net.Http.SystemProxyInfo");

View File

@@ -2,10 +2,11 @@
// Licensed under the MIT license.
using Microsoft.Windows.AppLifecycle;
using Windows.Win32.Foundation;
using Windows.Win32.Security;
using Windows.Win32.System.Com;
using static Windows.Win32.PInvoke;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Com;
using static Snap.Hutao.Win32.ConstValues;
using static Snap.Hutao.Win32.Kernel32;
using static Snap.Hutao.Win32.Ole32;
namespace Snap.Hutao.Core.LifeCycle;
@@ -18,7 +19,7 @@ internal static class AppInstanceExtension
private static readonly WaitCallback RunActionWaitCallback = RunAction;
// Hold the reference here to prevent memory corruption.
private static HANDLE redirectEventHandle = HANDLE.Null;
private static HANDLE redirectEventHandle;
/// <summary>
/// 同步非阻塞重定向
@@ -27,19 +28,24 @@ internal static class AppInstanceExtension
/// <param name="args">参数</param>
public static unsafe void RedirectActivationTo(this AppInstance appInstance, AppActivationArguments args)
{
redirectEventHandle = CreateEvent(default(SECURITY_ATTRIBUTES*), true, false, null);
// use ThreadPool.UnsafeQueueUserWorkItem to cancel stacktrace
// like ExecutionContext.SuppressFlow
ThreadPool.UnsafeQueueUserWorkItem(RunActionWaitCallback, () =>
try
{
appInstance.RedirectActivationToAsync(args).AsTask().Wait();
SetEvent(redirectEventHandle);
});
redirectEventHandle = CreateEventW(default, true, false, default);
ReadOnlySpan<HANDLE> handles = new(ref redirectEventHandle);
CoWaitForMultipleObjects((uint)CWMO_FLAGS.CWMO_DEFAULT, INFINITE, handles, out uint _);
CloseHandle(redirectEventHandle);
// use ThreadPool.UnsafeQueueUserWorkItem to cancel stacktrace
// like ExecutionContext.SuppressFlow
ThreadPool.UnsafeQueueUserWorkItem(RunActionWaitCallback, () =>
{
appInstance.RedirectActivationToAsync(args).AsTask().Wait();
SetEvent(redirectEventHandle);
});
CoWaitForMultipleObjects((uint)CWMO_FLAGS.CWMO_DEFAULT, INFINITE, [redirectEventHandle], out uint _);
}
finally
{
CloseHandle(redirectEventHandle);
}
}
[SuppressMessage("", "SH007")]

View File

@@ -3,7 +3,7 @@
using Microsoft.UI.Xaml;
using Snap.Hutao.Core.Windowing;
using Windows.Win32.Foundation;
using Snap.Hutao.Win32.Foundation;
using WinRT.Interop;
namespace Snap.Hutao.Core.LifeCycle;
@@ -19,6 +19,6 @@ internal static class CurrentWindowReferenceExtension
{
return reference.Window is IWindowOptionsSource optionsSource
? optionsSource.WindowOptions.Hwnd
: (HWND)WindowNative.GetWindowHandle(reference.Window);
: WindowNative.GetWindowHandle(reference.Window);
}
}

View File

@@ -2,9 +2,9 @@
// Licensed under the MIT license.
using Snap.Hutao.Core.Setting;
using Windows.Win32.Foundation;
using Windows.Win32.System.Console;
using static Windows.Win32.PInvoke;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Console;
using static Snap.Hutao.Win32.Kernel32;
namespace Snap.Hutao.Core.Logging;
@@ -26,7 +26,7 @@ internal sealed class ConsoleWindowLifeTime : IDisposable
SetConsoleMode(inputHandle, mode);
}
SetConsoleTitle("Snap Hutao Debug Console");
SetConsoleTitleW("Snap Hutao Debug Console");
}
}
}

View File

@@ -1,15 +1,14 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Com;
using Snap.Hutao.Win32.UI.Shell;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
using System.IO;
using System.Runtime.InteropServices;
using Windows.Storage;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
using Windows.Win32.UI.Shell;
using Windows.Win32.UI.WindowsAndMessaging;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.Macros;
using static Snap.Hutao.Win32.Ole32;
namespace Snap.Hutao.Core.Shell;
@@ -34,31 +33,44 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
return false;
}
HRESULT result = CoCreateInstance<ShellLink, IShellLinkW>(null, CLSCTX.CLSCTX_INPROC_SERVER, out IShellLinkW shellLink);
Marshal.ThrowExceptionForHR(result);
return UnsafeTryCreateDesktopShoutcutForElevatedLaunch(targetLogoPath);
}
shellLink.SetPath($"shell:AppsFolder\\{runtimeOptions.FamilyName}!App");
shellLink.SetShowCmd(SHOW_WINDOW_CMD.SW_NORMAL);
shellLink.SetIconLocation(targetLogoPath, 0);
private unsafe bool UnsafeTryCreateDesktopShoutcutForElevatedLaunch(string targetLogoPath)
{
bool result = false;
IShellLinkDataList shellLinkDataList = (IShellLinkDataList)shellLink;
shellLinkDataList.GetFlags(out uint flags);
flags |= (uint)SHELL_LINK_DATA_FLAGS.SLDF_RUNAS_USER;
shellLinkDataList.SetFlags(flags);
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string target = Path.Combine(desktop, $"{SH.FormatAppNameAndVersion(runtimeOptions.Version)}.lnk");
IPersistFile persistFile = (IPersistFile)shellLink;
try
// DO NOT revert if condition, COM interfaces need to be released properly
HRESULT hr = CoCreateInstance(ref ShellLink.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, ref IShellLinkW.IID, out IShellLinkW* pShellLink);
if (SUCCEEDED(hr))
{
persistFile.Save(target, false);
}
catch (UnauthorizedAccessException)
{
return false;
pShellLink->SetPath($"shell:AppsFolder\\{runtimeOptions.FamilyName}!App");
pShellLink->SetShowCmd(SHOW_WINDOW_CMD.SW_NORMAL);
pShellLink->SetIconLocation(targetLogoPath, 0);
if (SUCCEEDED(pShellLink->QueryInterface(ref IShellLinkDataList.IID, out IShellLinkDataList* pShellLinkDataList)))
{
pShellLinkDataList->GetFlags(out uint flags);
pShellLinkDataList->SetFlags(flags | (uint)SHELL_LINK_DATA_FLAGS.SLDF_RUNAS_USER);
pShellLinkDataList->Release();
}
if (SUCCEEDED(pShellLink->QueryInterface(ref IPersistFile.IID, out IPersistFile* pPersistFile)))
{
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string target = Path.Combine(desktop, $"{SH.FormatAppNameAndVersion(runtimeOptions.Version)}.lnk");
if (SUCCEEDED(pPersistFile->Save(target, false)))
{
result = true;
}
pPersistFile->Release();
}
pShellLink->Release();
}
return true;
return result;
}
}

View File

@@ -5,11 +5,11 @@ using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Model;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
using System.Text;
using Windows.System;
using Windows.Win32.Foundation;
using Windows.Win32.UI.Input.KeyboardAndMouse;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Core.Windowing.HotKey;

View File

@@ -1,9 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
using System.Runtime.InteropServices;
using Windows.Win32.UI.Input.KeyboardAndMouse;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Core.Windowing.HotKey;
@@ -14,7 +14,7 @@ internal sealed partial class HotKeyController : IHotKeyController
{
private static readonly WaitCallback RunMouseClickRepeatForever = MouseClickRepeatForever;
private readonly object locker = new();
private readonly object syncRoot = new();
private readonly HotKeyOptions hotKeyOptions;
@@ -75,7 +75,7 @@ internal sealed partial class HotKeyController : IHotKeyController
private void ToggleMouseClickRepeatForever()
{
lock (locker)
lock (syncRoot)
{
if (hotKeyOptions.IsMouseClickRepeatForeverOn)
{

View File

@@ -1,8 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
using Windows.System;
using Windows.Win32.UI.Input.KeyboardAndMouse;
namespace Snap.Hutao.Core.Windowing.HotKey;

View File

@@ -1,7 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Windows.Win32.UI.WindowsAndMessaging;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
namespace Snap.Hutao.Core.Windowing;

View File

@@ -9,13 +9,14 @@ using Microsoft.UI.Xaml.Media;
using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Service;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Graphics.Dwm;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
using System.IO;
using Windows.Graphics;
using Windows.UI;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Dwm;
using Windows.Win32.UI.WindowsAndMessaging;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.DwmApi;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Core.Windowing;
@@ -104,7 +105,7 @@ internal sealed class WindowController
return;
}
WINDOWPLACEMENT windowPlacement = Win32.StructMarshal.WINDOWPLACEMENT();
WINDOWPLACEMENT windowPlacement = WINDOWPLACEMENT.Create();
GetWindowPlacement(options.Hwnd, ref windowPlacement);
// prevent save value when we are maximized.
@@ -194,7 +195,7 @@ internal sealed class WindowController
private unsafe void UpdateImmersiveDarkMode(FrameworkElement titleBar, object discard)
{
BOOL isDarkMode = Control.Theme.ThemeHelper.IsDarkMode(titleBar.ActualTheme);
DwmSetWindowAttribute(options.Hwnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, &isDarkMode, unchecked((uint)sizeof(BOOL)));
DwmSetWindowAttribute(options.Hwnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref isDarkMode);
}
private void UpdateDragRectangles()

View File

@@ -2,11 +2,11 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
using System.Runtime.CompilerServices;
using Windows.Win32.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;
using WinRT.Interop;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Core.Windowing;
@@ -24,8 +24,8 @@ internal static class WindowExtension
public static void SetLayeredWindow(this Window window)
{
HWND hwnd = (HWND)WindowNative.GetWindowHandle(window);
nint style = GetWindowLongPtr(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE);
nint style = GetWindowLongPtrW(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE);
style |= (nint)WINDOW_EX_STYLE.WS_EX_LAYERED;
SetWindowLongPtr(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, style);
SetWindowLongPtrW(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, style);
}
}

View File

@@ -4,10 +4,10 @@
using Microsoft.UI.Input;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Snap.Hutao.Win32.Foundation;
using Windows.Graphics;
using Windows.Win32.Foundation;
using WinRT.Interop;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Core.Windowing;
@@ -55,7 +55,7 @@ internal readonly struct WindowOptions
/// <param name="persistSize">持久化尺寸</param>
public WindowOptions(Window window, FrameworkElement titleBar, SizeInt32 initSize, bool persistSize = false)
{
Hwnd = (HWND)WindowNative.GetWindowHandle(window);
Hwnd = WindowNative.GetWindowHandle(window);
InputNonClientPointerSource = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id);
TitleBar = titleBar;
InitSize = initSize;
@@ -80,8 +80,8 @@ internal readonly struct WindowOptions
{
HWND fgHwnd = GetForegroundWindow();
uint threadIdHwnd = GetWindowThreadProcessId(Hwnd);
uint threadIdFgHwnd = GetWindowThreadProcessId(fgHwnd);
uint threadIdHwnd = GetWindowThreadProcessId(Hwnd, default);
uint threadIdFgHwnd = GetWindowThreadProcessId(fgHwnd, default);
if (threadIdHwnd != threadIdFgHwnd)
{

View File

@@ -4,10 +4,13 @@
using Microsoft.UI.Xaml;
using Snap.Hutao.Core.Windowing.Backdrop;
using Snap.Hutao.Core.Windowing.HotKey;
using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell;
using Windows.Win32.UI.WindowsAndMessaging;
using static Windows.Win32.PInvoke;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.UI.Shell;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
using System.Runtime.InteropServices;
using static Snap.Hutao.Win32.ComCtl32;
using static Snap.Hutao.Win32.ConstValues;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Core.Windowing;
@@ -26,8 +29,8 @@ internal sealed class WindowSubclass : IDisposable
private readonly IHotKeyController hotKeyController;
// We have to explicitly hold a reference to SUBCLASSPROC
private SUBCLASSPROC? windowProc;
private SUBCLASSPROC? legacyDragBarProc;
private SUBCLASSPROC windowProc = default!;
private SUBCLASSPROC legacyDragBarProc = default!;
public WindowSubclass(Window window, in WindowOptions options, IServiceProvider serviceProvider)
{
@@ -57,7 +60,7 @@ internal sealed class WindowSubclass : IDisposable
}
titleBarHooked = false;
HWND hwndDragBar = FindWindowEx(options.Hwnd, default, "DRAG_BAR_WINDOW_CLASS", default);
HWND hwndDragBar = FindWindowExW(options.Hwnd, default, "DRAG_BAR_WINDOW_CLASS", default);
if (hwndDragBar.IsNull)
{
@@ -76,12 +79,12 @@ internal sealed class WindowSubclass : IDisposable
hotKeyController.UnregisterAll();
RemoveWindowSubclass(options.Hwnd, windowProc, WindowSubclassId);
windowProc = null;
windowProc = default!;
if (options.UseLegacyDragBarImplementation)
{
RemoveWindowSubclass(options.Hwnd, legacyDragBarProc, DragBarSubclassId);
legacyDragBarProc = null;
legacyDragBarProc = default!;
}
}

View File

@@ -3,13 +3,14 @@
using Snap.Hutao.Core.IO;
using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Com;
using Snap.Hutao.Win32.UI.Shell;
using Snap.Hutao.Win32.UI.Shell.Common;
using System.Runtime.InteropServices;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
using Windows.Win32.UI.Shell;
using Windows.Win32.UI.Shell.Common;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.Macros;
using static Snap.Hutao.Win32.Ole32;
using static Snap.Hutao.Win32.Shell32;
namespace Snap.Hutao.Factory.Picker;
@@ -21,32 +22,33 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
public unsafe ValueResult<bool, ValueFile> PickFile(string? title, string? defaultFileName, (string Name, string Type)[]? filters)
{
CoCreateInstance<FileOpenDialog, IFileOpenDialog>(default, CLSCTX.CLSCTX_INPROC_SERVER, out IFileOpenDialog dialog).ThrowOnFailure();
HRESULT hr = CoCreateInstance(ref FileOpenDialog.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, ref IFileDialog.IID, out IFileDialog* pFileDialog);
Marshal.ThrowExceptionForHR(hr);
FILEOPENDIALOGOPTIONS options =
FILEOPENDIALOGOPTIONS.FOS_NOTESTFILECREATE |
FILEOPENDIALOGOPTIONS.FOS_FORCEFILESYSTEM |
FILEOPENDIALOGOPTIONS.FOS_NOCHANGEDIR;
dialog.SetOptions(options);
SetDesktopAsStartupFolder(dialog);
if (!string.IsNullOrEmpty(title))
{
dialog.SetTitle(title);
}
pFileDialog->SetOptions(options);
SetDesktopAsStartupFolder(pFileDialog);
if (!string.IsNullOrEmpty(defaultFileName))
{
dialog.SetFileName(defaultFileName);
pFileDialog->SetFileName(defaultFileName);
}
if (!string.IsNullOrEmpty(title))
{
pFileDialog->SetTitle(title);
}
if (filters is { Length: > 0 })
{
SetFileTypes(dialog, filters);
SetFileTypes(pFileDialog, filters);
}
HRESULT res = dialog.Show(currentWindowReference.GetWindowHandle());
HRESULT res = pFileDialog->Show(currentWindowReference.GetWindowHandle());
if (res == HRESULT_FROM_WIN32(WIN32_ERROR.ERROR_CANCELLED))
{
return new(false, default);
@@ -56,18 +58,18 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
Marshal.ThrowExceptionForHR(res);
}
dialog.GetResult(out IShellItem item);
HRESULT t = pFileDialog->GetResult(out IShellItem* pShellItem);
PWSTR displayName = default;
string file;
try
{
item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out displayName);
file = new((char*)displayName);
pShellItem->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out displayName);
file = new(displayName);
}
finally
{
Marshal.FreeCoTaskMem((nint)displayName.Value);
CoTaskMemFree(displayName);
}
return new(true, file);
@@ -75,7 +77,8 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
public unsafe ValueResult<bool, ValueFile> SaveFile(string? title, string? defaultFileName, (string Name, string Type)[]? filters)
{
CoCreateInstance<FileSaveDialog, IFileSaveDialog>(default, CLSCTX.CLSCTX_INPROC_SERVER, out IFileSaveDialog dialog).ThrowOnFailure();
HRESULT hr = CoCreateInstance(ref FileSaveDialog.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, ref IFileDialog.IID, out IFileDialog* pFileDialog);
Marshal.ThrowExceptionForHR(hr);
FILEOPENDIALOGOPTIONS options =
FILEOPENDIALOGOPTIONS.FOS_NOTESTFILECREATE |
@@ -83,25 +86,25 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
FILEOPENDIALOGOPTIONS.FOS_STRICTFILETYPES |
FILEOPENDIALOGOPTIONS.FOS_NOCHANGEDIR;
dialog.SetOptions(options);
SetDesktopAsStartupFolder(dialog);
if (!string.IsNullOrEmpty(title))
{
dialog.SetTitle(title);
}
pFileDialog->SetOptions(options);
SetDesktopAsStartupFolder(pFileDialog);
if (!string.IsNullOrEmpty(defaultFileName))
{
dialog.SetFileName(defaultFileName);
pFileDialog->SetFileName(defaultFileName);
}
if (!string.IsNullOrEmpty(title))
{
pFileDialog->SetTitle(title);
}
if (filters is { Length: > 0 })
{
SetFileTypes(dialog, filters);
SetFileTypes(pFileDialog, filters);
}
HRESULT res = dialog.Show(currentWindowReference.GetWindowHandle());
HRESULT res = pFileDialog->Show(currentWindowReference.GetWindowHandle());
if (res == HRESULT_FROM_WIN32(WIN32_ERROR.ERROR_CANCELLED))
{
return new(false, default);
@@ -111,18 +114,18 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
Marshal.ThrowExceptionForHR(res);
}
dialog.GetResult(out IShellItem item);
pFileDialog->GetResult(out IShellItem* pShellItem);
PWSTR displayName = default;
string file;
try
{
item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out displayName);
file = new((char*)displayName);
pShellItem->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out displayName);
file = new(displayName);
}
finally
{
Marshal.FreeCoTaskMem((nint)displayName.Value);
CoTaskMemFree(displayName);
}
return new(true, file);
@@ -130,7 +133,8 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
public unsafe ValueResult<bool, string> PickFolder(string? title)
{
CoCreateInstance<FileOpenDialog, IFileOpenDialog>(default, CLSCTX.CLSCTX_INPROC_SERVER, out IFileOpenDialog dialog).ThrowOnFailure();
HRESULT hr = CoCreateInstance(ref FileOpenDialog.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, ref IFileDialog.IID, out IFileDialog* pFileDialog);
Marshal.ThrowExceptionForHR(hr);
FILEOPENDIALOGOPTIONS options =
FILEOPENDIALOGOPTIONS.FOS_NOTESTFILECREATE |
@@ -138,15 +142,15 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
FILEOPENDIALOGOPTIONS.FOS_PICKFOLDERS |
FILEOPENDIALOGOPTIONS.FOS_NOCHANGEDIR;
dialog.SetOptions(options);
SetDesktopAsStartupFolder(dialog);
pFileDialog->SetOptions(options);
SetDesktopAsStartupFolder(pFileDialog);
if (!string.IsNullOrEmpty(title))
{
dialog.SetTitle(title);
pFileDialog->SetTitle(title);
}
HRESULT res = dialog.Show(currentWindowReference.GetWindowHandle());
HRESULT res = pFileDialog->Show(currentWindowReference.GetWindowHandle());
if (res == HRESULT_FROM_WIN32(WIN32_ERROR.ERROR_CANCELLED))
{
return new(false, default!);
@@ -156,25 +160,24 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
Marshal.ThrowExceptionForHR(res);
}
dialog.GetResult(out IShellItem item);
pFileDialog->GetResult(out IShellItem* pShellItem);
PWSTR displayName = default;
string file;
try
{
item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out displayName);
pShellItem->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out displayName);
file = new((char*)displayName);
}
finally
{
Marshal.FreeCoTaskMem((nint)displayName.Value);
CoTaskMemFree(displayName);
}
return new(true, file);
}
private static unsafe void SetFileTypes<TDialog>(TDialog dialog, (string Name, string Type)[] filters)
where TDialog : IFileDialog
private static unsafe void SetFileTypes(IFileDialog* pFileDialog, (string Name, string Type)[] filters)
{
List<nint> unmanagedStringPtrs = new(filters.Length * 2);
List<COMDLG_FILTERSPEC> filterSpecs = new(filters.Length);
@@ -190,10 +193,7 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
filterSpecs.Add(spec);
}
fixed (COMDLG_FILTERSPEC* ptr = CollectionsMarshal.AsSpan(filterSpecs))
{
dialog.SetFileTypes((uint)filterSpecs.Count, ptr);
}
pFileDialog->SetFileTypes(CollectionsMarshal.AsSpan(filterSpecs));
foreach (ref readonly nint ptr in CollectionsMarshal.AsSpan(unmanagedStringPtrs))
{
@@ -201,11 +201,11 @@ internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInt
}
}
private static unsafe void SetDesktopAsStartupFolder<TDialog>(TDialog dialog)
where TDialog : IFileDialog
private static unsafe void SetDesktopAsStartupFolder(IFileDialog* pFileDialog)
{
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
SHCreateItemFromParsingName(desktopPath, default, typeof(IShellItem).GUID, out object shellItem).ThrowOnFailure();
dialog.SetFolder((IShellItem)shellItem);
HRESULT hr = SHCreateItemFromParsingName(desktopPath, default, ref IShellItem.IID, out IShellItem* pShellItem);
Marshal.ThrowExceptionForHR(hr);
pFileDialog->SetFolder(pShellItem);
}
}

View File

@@ -3,7 +3,7 @@
using Microsoft.UI.Xaml;
using Snap.Hutao.Core.Windowing;
using Windows.Win32.UI.WindowsAndMessaging;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
namespace Snap.Hutao;
@@ -32,9 +32,9 @@ internal sealed partial class GuideWindow : Window, IWindowOptionsSource, IMinMa
public unsafe void HandleMinMaxInfo(ref MINMAXINFO info, double scalingFactor)
{
info.ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, info.ptMinTrackSize.X);
info.ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, info.ptMinTrackSize.Y);
info.ptMaxTrackSize.X = (int)Math.Min(MaxWidth * scalingFactor, info.ptMaxTrackSize.X);
info.ptMaxTrackSize.Y = (int)Math.Min(MaxHeight * scalingFactor, info.ptMaxTrackSize.Y);
info.ptMinTrackSize.x = (int)Math.Max(MinWidth * scalingFactor, info.ptMinTrackSize.x);
info.ptMinTrackSize.y = (int)Math.Max(MinHeight * scalingFactor, info.ptMinTrackSize.y);
info.ptMaxTrackSize.x = (int)Math.Min(MaxWidth * scalingFactor, info.ptMaxTrackSize.x);
info.ptMaxTrackSize.y = (int)Math.Min(MaxHeight * scalingFactor, info.ptMaxTrackSize.y);
}
}
}

View File

@@ -4,7 +4,7 @@
using Microsoft.UI.Xaml;
using Snap.Hutao.Core.Windowing;
using Snap.Hutao.ViewModel.Game;
using Windows.Win32.UI.WindowsAndMessaging;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
namespace Snap.Hutao;
@@ -50,9 +50,9 @@ internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOpt
/// <inheritdoc/>
public unsafe void HandleMinMaxInfo(ref MINMAXINFO info, double scalingFactor)
{
info.ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, info.ptMinTrackSize.X);
info.ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, info.ptMinTrackSize.Y);
info.ptMaxTrackSize.X = (int)Math.Min(MaxWidth * scalingFactor, info.ptMaxTrackSize.X);
info.ptMaxTrackSize.Y = (int)Math.Min(MaxHeight * scalingFactor, info.ptMaxTrackSize.Y);
info.ptMinTrackSize.x = (int)Math.Max(MinWidth * scalingFactor, info.ptMinTrackSize.x);
info.ptMinTrackSize.y = (int)Math.Max(MinHeight * scalingFactor, info.ptMinTrackSize.y);
info.ptMaxTrackSize.x = (int)Math.Min(MaxWidth * scalingFactor, info.ptMaxTrackSize.x);
info.ptMaxTrackSize.y = (int)Math.Min(MaxHeight * scalingFactor, info.ptMaxTrackSize.y);
}
}

View File

@@ -3,7 +3,7 @@
using Microsoft.UI.Xaml;
using Snap.Hutao.Core.Windowing;
using Windows.Win32.UI.WindowsAndMessaging;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
namespace Snap.Hutao;
@@ -37,7 +37,7 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMax
/// <inheritdoc/>
public unsafe void HandleMinMaxInfo(ref MINMAXINFO pInfo, double scalingFactor)
{
pInfo.ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, pInfo.ptMinTrackSize.X);
pInfo.ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, pInfo.ptMinTrackSize.Y);
pInfo.ptMinTrackSize.x = (int)Math.Max(MinWidth * scalingFactor, pInfo.ptMinTrackSize.x);
pInfo.ptMinTrackSize.y = (int)Math.Max(MinHeight * scalingFactor, pInfo.ptMinTrackSize.y);
}
}

View File

@@ -7,12 +7,12 @@ using Snap.Hutao.Model;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
using Snap.Hutao.Service.Game.PathAbstraction;
using Snap.Hutao.Win32.Graphics.Gdi;
using System.Collections.Immutable;
using System.Globalization;
using Windows.Graphics;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Gdi;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.Gdi32;
using static Snap.Hutao.Win32.User32;
namespace Snap.Hutao.Service.Game;
@@ -82,12 +82,12 @@ internal sealed class LaunchOptions : DbStoreOptions
HDC hDC = default;
try
{
hDC = GetDC(HWND.Null);
hDC = GetDC(default);
fps = GetDeviceCaps(hDC, GET_DEVICE_CAPS_INDEX.VREFRESH);
}
finally
{
_ = ReleaseDC(HWND.Null, hDC);
_ = ReleaseDC(default, hDC);
}
}
}

View File

@@ -1,7 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Windows.Win32.Foundation;
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Service.Game.Launching.Handler;

View File

@@ -2,11 +2,11 @@
// Licensed under the MIT license.
using Snap.Hutao.Core.Diagnostics;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Memory;
using Snap.Hutao.Win32.System.ProcessStatus;
using System.Runtime.InteropServices;
using Windows.Win32.Foundation;
using Windows.Win32.System.ProcessStatus;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.Kernel32;
namespace Snap.Hutao.Service.Game.Unlocker;
@@ -61,36 +61,29 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
ref readonly Module userAssembly = ref moduleEntryInfo.UserAssembly;
memory = new VirtualMemory(unityPlayer.Size + userAssembly.Size);
byte* lpBuffer = (byte*)memory.Pointer;
return ReadProcessMemory((HANDLE)process.Handle, (void*)unityPlayer.Address, lpBuffer, unityPlayer.Size)
&& ReadProcessMemory((HANDLE)process.Handle, (void*)userAssembly.Address, lpBuffer + unityPlayer.Size, userAssembly.Size);
return ReadProcessMemory(process.Handle, (void*)unityPlayer.Address, memory.AsSpan()[..(int)unityPlayer.Size], out _)
&& ReadProcessMemory(process.Handle, (void*)userAssembly.Address, memory.AsSpan()[(int)unityPlayer.Size..], out _);
}
private static unsafe bool UnsafeReadProcessMemory(System.Diagnostics.Process process, nuint baseAddress, out nuint value)
{
ulong temp = 0;
bool result = ReadProcessMemory((HANDLE)process.Handle, (void*)baseAddress, (byte*)&temp, 8);
value = 0;
bool result = ReadProcessMemory((HANDLE)process.Handle, (void*)baseAddress, ref value, out _);
Verify.Operation(result, SH.ServiceGameUnlockerReadProcessMemoryPointerAddressFailed);
value = (nuint)temp;
return result;
}
private static unsafe bool UnsafeWriteProcessMemory(System.Diagnostics.Process process, nuint baseAddress, int value)
{
return WriteProcessMemory((HANDLE)process.Handle, (void*)baseAddress, &value, sizeof(int));
return WriteProcessMemory((HANDLE)process.Handle, (void*)baseAddress, ref value, out _);
}
private static unsafe FindModuleResult UnsafeTryFindModule(in HANDLE hProcess, in ReadOnlySpan<char> moduleName, out Module module)
{
HMODULE[] buffer = new HMODULE[128];
uint actualSize;
fixed (HMODULE* pBuffer = buffer)
if (!K32EnumProcessModules(hProcess, buffer, out uint actualSize))
{
if (!K32EnumProcessModules(hProcess, pBuffer, unchecked((uint)(buffer.Length * sizeof(HMODULE))), out actualSize))
{
Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError());
}
Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError());
}
if (actualSize == 0)
@@ -99,18 +92,17 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
return FindModuleResult.NoModuleFound;
}
Span<HMODULE> modules = new(buffer, 0, unchecked((int)(actualSize / sizeof(HMODULE))));
foreach (ref readonly HMODULE hModule in modules)
foreach (ref readonly HMODULE hModule in buffer.AsSpan()[..(int)(actualSize / sizeof(HMODULE))])
{
char[] baseName = new char[256];
if (K32GetModuleBaseNameW(hProcess, hModule, baseName) == 0)
{
continue;
}
fixed (char* lpBaseName = baseName)
{
if (K32GetModuleBaseName(hProcess, hModule, lpBaseName, 256) == 0)
{
continue;
}
ReadOnlySpan<char> szModuleName = MemoryMarshal.CreateReadOnlySpanFromNullTerminated(lpBaseName);
if (!szModuleName.SequenceEqual(moduleName))
{
@@ -118,7 +110,7 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
}
}
if (!K32GetModuleInformation(hProcess, hModule, out MODULEINFO moduleInfo, unchecked((uint)sizeof(MODULEINFO))))
if (!K32GetModuleInformation(hProcess, hModule, out MODULEINFO moduleInfo))
{
continue;
}

View File

@@ -334,9 +334,6 @@
</ItemGroup>
<!-- Projects -->
<ItemGroup>
<ProjectReference Include="..\Snap.Hutao.Win32\Snap.Hutao.Win32.csproj" />
</ItemGroup>
<!-- Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget

View File

@@ -0,0 +1,37 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Registry;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
[SuppressMessage("", "SH002")]
[SuppressMessage("", "SYSLIB1054")]
internal static class AdvApi32
{
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern WIN32_ERROR RegCloseKey(HKEY hKey);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern WIN32_ERROR RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, REG_NOTIFY_FILTER dwNotifyFilter, [AllowNull] HANDLE hEvent, BOOL fAsynchronous);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern WIN32_ERROR RegOpenKeyExW(HKEY hKey, [AllowNull] PCWSTR lpSubKey, [AllowNull] uint ulOptions, REG_SAM_FLAGS samDesired, [Out] HKEY* phkResult);
public static unsafe WIN32_ERROR RegOpenKeyExW(HKEY hKey, ReadOnlySpan<char> subKey, uint ulOptions, REG_SAM_FLAGS samDesired, out HKEY hkResult)
{
fixed (char* lpSubKey = subKey)
{
fixed (HKEY* phkResult = &hkResult)
{
return RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult);
}
}
}
}

View File

@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.UI.Shell;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class ComCtl32
{
[DllImport("COMCTL32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern LRESULT DefSubclassProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam);
[DllImport("COMCTL32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern BOOL RemoveWindowSubclass(HWND hWnd, [MarshalAs(UnmanagedType.FunctionPtr)] SUBCLASSPROC pfnSubclass, nuint uIdSubclass);
[DllImport("COMCTL32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL SetWindowSubclass(HWND hWnd, [MarshalAs(UnmanagedType.FunctionPtr)] SUBCLASSPROC pfnSubclass, nuint uIdSubclass, nuint dwRefData);
}

View File

@@ -0,0 +1,16 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32;
[SuppressMessage("", "SA1310")]
internal static class ConstValues
{
public const uint WM_NULL = 0x00000000U;
public const uint WM_ERASEBKGND = 0x00000014U;
public const uint WM_GETMINMAXINFO = 0x00000024U;
public const uint WM_NCRBUTTONDOWN = 0x000000A4U;
public const uint WM_NCRBUTTONUP = 0x000000A5U;
public const uint WM_HOTKEY = 0x00000312U;
public const uint INFINITE = 0xFFFFFFFFU;
}

View File

@@ -0,0 +1,27 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Graphics.Dwm;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
[SuppressMessage("", "SH002")]
[SuppressMessage("", "SYSLIB1054")]
internal static class DwmApi
{
[DllImport("dwmapi.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows6.0.6000")]
public static unsafe extern HRESULT DwmSetWindowAttribute(HWND hwnd, uint dwAttribute, void* pvAttribute, uint cbAttribute);
public static unsafe HRESULT DwmSetWindowAttribute<T>(HWND hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref readonly T attribute)
where T : unmanaged
{
fixed (T* pvAttribute = &attribute)
{
return DwmSetWindowAttribute(hwnd, (uint)dwAttribute, &pvAttribute, (uint)sizeof(T));
}
}
}

View File

@@ -0,0 +1,17 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct BOOL
{
public readonly int Value;
public BOOL(bool value) => Value = value ? 1 : 0;
public static unsafe implicit operator int(BOOL value) => *(int*)&value;
public static implicit operator BOOL(bool value) => new(value);
public static implicit operator bool(BOOL value) => value.Value != 0;
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
[SuppressMessage("", "SA1307")]
internal readonly struct FILETIME
{
public readonly uint dwLowDateTime;
public readonly uint dwHighDateTime;
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct HANDLE
{
public readonly nint Value;
public static unsafe implicit operator HANDLE(nint value) => *(HANDLE*)&value;
}

View File

@@ -0,0 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct HMODULE
{
public readonly nint Value;
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Diagnostics;
namespace Snap.Hutao.Win32.Foundation;
[SuppressMessage("", "SA1310")]
internal readonly partial struct HRESULT
{
public static readonly HRESULT E_FAIL = unchecked((int)0x80004005);
public readonly int Value;
public static unsafe implicit operator int(HRESULT value) => *(int*)&value;
public static unsafe implicit operator HRESULT(int value) => *(HRESULT*)&value;
}
#if DEBUG
[DebuggerDisplay("{DebuggerDisplay}")]
internal readonly partial struct HRESULT
{
private string DebuggerDisplay => $"0x{Value:X8}";
}
#endif

View File

@@ -0,0 +1,15 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct HWND
{
public readonly nint Value;
public HWND(nint value) => Value = value;
public bool IsNull => Value is 0;
public static unsafe implicit operator HWND(nint value) => *(HWND*)&value;
}

View File

@@ -0,0 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct LPARAM
{
public readonly nint Value;
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct LRESULT
{
public readonly nint Value;
public static unsafe implicit operator LRESULT(nint value) => *(LRESULT*)&value;
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct PCWSTR
{
public readonly unsafe char* Value;
public static unsafe implicit operator PCWSTR(char* value) => *(PCWSTR*)&value;
public static unsafe implicit operator char*(PCWSTR value) => *(char**)&value;
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
[SuppressMessage("", "SA1307")]
internal struct POINT
{
public int x;
public int y;
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct PWSTR
{
public readonly unsafe char* Value;
public static unsafe implicit operator PWSTR(char* value) => *(PWSTR*)&value;
public static unsafe implicit operator char*(PWSTR value) => *(char**)&value;
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
[SuppressMessage("", "SA1307")]
internal readonly struct RECT
{
public readonly int left;
public readonly int top;
public readonly int right;
public readonly int bottom;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Foundation;
internal readonly struct WPARAM
{
public readonly nuint Value;
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Graphics.Gdi;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
internal static class Gdi32
{
[DllImport("GDI32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern int GetDeviceCaps([AllowNull] HDC hdc, int index);
public static int GetDeviceCaps([AllowNull] HDC hdc, GET_DEVICE_CAPS_INDEX index)
{
return GetDeviceCaps(hdc, (int)index);
}
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Graphics.Dwm;
internal enum DWMWINDOWATTRIBUTE
{
DWMWA_NCRENDERING_ENABLED = 1,
DWMWA_NCRENDERING_POLICY = 2,
DWMWA_TRANSITIONS_FORCEDISABLED = 3,
DWMWA_ALLOW_NCPAINT = 4,
DWMWA_CAPTION_BUTTON_BOUNDS = 5,
DWMWA_NONCLIENT_RTL_LAYOUT = 6,
DWMWA_FORCE_ICONIC_REPRESENTATION = 7,
DWMWA_FLIP3D_POLICY = 8,
DWMWA_EXTENDED_FRAME_BOUNDS = 9,
DWMWA_HAS_ICONIC_BITMAP = 10,
DWMWA_DISALLOW_PEEK = 11,
DWMWA_EXCLUDED_FROM_PEEK = 12,
DWMWA_CLOAK = 13,
DWMWA_CLOAKED = 14,
DWMWA_FREEZE_REPRESENTATION = 15,
DWMWA_PASSIVE_UPDATE_MODE = 16,
DWMWA_USE_HOSTBACKDROPBRUSH = 17,
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
DWMWA_BORDER_COLOR = 34,
DWMWA_CAPTION_COLOR = 35,
DWMWA_TEXT_COLOR = 36,
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37,
DWMWA_SYSTEMBACKDROP_TYPE = 38,
DWMWA_LAST = 39,
}

View File

@@ -0,0 +1,48 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Graphics.Gdi;
internal enum GET_DEVICE_CAPS_INDEX : uint
{
DRIVERVERSION = 0u,
TECHNOLOGY = 2u,
HORZSIZE = 4u,
VERTSIZE = 6u,
HORZRES = 8u,
VERTRES = 10u,
BITSPIXEL = 12u,
PLANES = 14u,
NUMBRUSHES = 16u,
NUMPENS = 18u,
NUMMARKERS = 20u,
NUMFONTS = 22u,
NUMCOLORS = 24u,
PDEVICESIZE = 26u,
CURVECAPS = 28u,
LINECAPS = 30u,
POLYGONALCAPS = 32u,
TEXTCAPS = 34u,
CLIPCAPS = 36u,
RASTERCAPS = 38u,
ASPECTX = 40u,
ASPECTY = 42u,
ASPECTXY = 44u,
LOGPIXELSX = 88u,
LOGPIXELSY = 90u,
SIZEPALETTE = 104u,
NUMRESERVED = 106u,
COLORRES = 108u,
PHYSICALWIDTH = 110u,
PHYSICALHEIGHT = 111u,
PHYSICALOFFSETX = 112u,
PHYSICALOFFSETY = 113u,
SCALINGFACTORX = 114u,
SCALINGFACTORY = 115u,
VREFRESH = 116u,
DESKTOPVERTRES = 117u,
DESKTOPHORZRES = 118u,
BLTALIGNMENT = 119u,
SHADEBLENDCAPS = 120u,
COLORMGMTCAPS = 121u,
}

View File

@@ -0,0 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Graphics.Gdi;
internal readonly struct HDC
{
public readonly nint Value;
}

View File

@@ -0,0 +1,140 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Security;
using Snap.Hutao.Win32.System.Console;
using Snap.Hutao.Win32.System.ProcessStatus;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
internal static class Kernel32
{
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
public static extern BOOL AllocConsole();
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL CloseHandle(HANDLE hObject);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern HANDLE CreateEventW([AllowNull] SECURITY_ATTRIBUTES* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, [AllowNull] PCWSTR lpName);
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
public static extern BOOL FreeConsole();
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
public static unsafe extern BOOL GetConsoleMode(HANDLE hConsoleHandle, CONSOLE_MODE* lpMode);
[SuppressMessage("", "SH002")]
public static unsafe BOOL GetConsoleMode(HANDLE hConsoleHandle, out CONSOLE_MODE mode)
{
fixed (CONSOLE_MODE* lpMode = &mode)
{
return GetConsoleMode(hConsoleHandle, lpMode);
}
}
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
public static extern HANDLE GetStdHandle(STD_HANDLE nStdHandle);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
public static unsafe extern BOOL K32EnumProcessModules(HANDLE hProcess, HMODULE* lphModule, uint cb, uint* lpcbNeeded);
public static unsafe BOOL K32EnumProcessModules(HANDLE hProcess, Span<HMODULE> hModules, out uint cbNeeded)
{
fixed (HMODULE* lphModule = hModules)
{
fixed (uint* lpcbNeeded = &cbNeeded)
{
return K32EnumProcessModules(hProcess, lphModule, (uint)(hModules.Length * sizeof(HMODULE)), lpcbNeeded);
}
}
}
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern uint K32GetModuleBaseNameW(HANDLE hProcess, [AllowNull] HMODULE hModule, PWSTR lpBaseName, uint nSize);
public static unsafe uint K32GetModuleBaseNameW(HANDLE hProcess, [AllowNull] HMODULE hModule, Span<char> baseName)
{
fixed (char* lpBaseName = baseName)
{
return K32GetModuleBaseNameW(hProcess, hModule, lpBaseName, (uint)baseName.Length);
}
}
[DllImport("KERNEL32.dll", ExactSpelling = true)]
public static unsafe extern BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, [Out] MODULEINFO* lpmodinfo, [In] uint cb);
public static unsafe BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, out MODULEINFO modinfo)
{
fixed (MODULEINFO* lpmodinfo = &modinfo)
{
return K32GetModuleInformation(hProcess, hModule, lpmodinfo, (uint)sizeof(MODULEINFO));
}
}
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, [MaybeNull] nuint* lpNumberOfBytesRead);
public static unsafe BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, Span<byte> buffer, [MaybeNull] out nuint numberOfBytesRead)
{
fixed (byte* lpBuffer = buffer)
{
fixed (nuint* lpNumberOfBytesRead = &numberOfBytesRead)
{
return ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, (uint)buffer.Length, lpNumberOfBytesRead);
}
}
}
public static unsafe BOOL ReadProcessMemory<T>(HANDLE hProcess, void* lpBaseAddress, ref T buffer, [MaybeNull] out nuint numberOfBytesRead)
where T : unmanaged
{
fixed (T* lpBuffer = &buffer)
{
fixed (nuint* lpNumberOfBytesRead = &numberOfBytesRead)
{
return ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, (uint)sizeof(T), lpNumberOfBytesRead);
}
}
}
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
public static extern BOOL SetConsoleMode(HANDLE hConsoleHandle, CONSOLE_MODE dwMode);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
public static extern BOOL SetConsoleTitleW(PCWSTR lpConsoleTitle);
public static unsafe BOOL SetConsoleTitleW(string consoleTitle)
{
fixed (char* lpConsoleTitle = consoleTitle)
{
return SetConsoleTitleW(lpConsoleTitle);
}
}
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern BOOL SetEvent(HANDLE hEvent);
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL WriteProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, nuint* lpNumberOfBytesWritten);
public static unsafe BOOL WriteProcessMemory<T>(HANDLE hProcess, void* lpBaseAddress, ref readonly T buffer, out nuint numberOfBytesWritten)
where T : unmanaged
{
fixed (T* lpBuffer = &buffer)
{
fixed (nuint* lpNumberOfBytesWritten = &numberOfBytesWritten)
{
return WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, (uint)sizeof(T), lpNumberOfBytesWritten);
}
}
}
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
namespace Snap.Hutao.Win32;
internal static class Macros
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SUCCEEDED(HRESULT hr)
{
return hr >= 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static HRESULT HRESULT_FROM_WIN32(WIN32_ERROR x)
{
return x <= 0 ? (int)x : (int)(((uint)x & 0x0000FFFFU) | ((uint)FACILITY_CODE.FACILITY_WIN32 << 16) | 0x80000000U);
}
}

View File

@@ -1,8 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Windows.Win32.System.Memory;
using static Windows.Win32.PInvoke;
using System.Runtime.InteropServices;
namespace Snap.Hutao.Win32.Memory;
@@ -28,8 +27,7 @@ internal readonly unsafe struct VirtualMemory : IUnmanagedMemory
public unsafe VirtualMemory(uint dwSize)
{
size = dwSize;
VIRTUAL_ALLOCATION_TYPE commitAndReserve = VIRTUAL_ALLOCATION_TYPE.MEM_COMMIT | VIRTUAL_ALLOCATION_TYPE.MEM_RESERVE;
pointer = VirtualAlloc(default, dwSize, commitAndReserve, PAGE_PROTECTION_FLAGS.PAGE_READWRITE);
pointer = NativeMemory.Alloc(dwSize);
}
/// <inheritdoc/>
@@ -41,6 +39,6 @@ internal readonly unsafe struct VirtualMemory : IUnmanagedMemory
/// <inheritdoc/>
public void Dispose()
{
VirtualFree(pointer, 0, VIRTUAL_FREE_TYPE.MEM_RELEASE);
NativeMemory.Free(pointer);
}
}

View File

@@ -0,0 +1,50 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Com;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
internal static class Ole32
{
[DllImport("OLE32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern HRESULT CoCreateInstance(Guid* rclsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, Guid* riid, void** ppv);
public static unsafe HRESULT CoCreateInstance<T>(ref readonly Guid clsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, ref readonly Guid iid, out T* pv)
where T : unmanaged
{
fixed (Guid* rclsid = &clsid)
{
fixed (Guid* riid = &iid)
{
fixed (T** ppv = &pv)
{
return CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, (void**)ppv);
}
}
}
}
[DllImport("OLE32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern void CoTaskMemFree([AllowNull] void* pv);
[DllImport("OLE32.dll", ExactSpelling = true)]
public static unsafe extern HRESULT CoWaitForMultipleObjects(uint dwFlags, uint dwTimeout, uint cHandles, HANDLE* pHandles, uint* lpdwindex);
[SuppressMessage("", "SH002")]
public static unsafe HRESULT CoWaitForMultipleObjects(uint dwFlags, uint dwTimeout, ReadOnlySpan<HANDLE> handles, out uint dwindex)
{
fixed (HANDLE* pHandles = handles)
{
fixed (uint* lpdwindex = &dwindex)
{
return CoWaitForMultipleObjects(dwFlags, dwTimeout, (uint)handles.Length, pHandles, lpdwindex);
}
}
}
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Registry;
[SuppressMessage("", "SA1310")]
internal readonly struct HKEY
{
public static readonly HKEY HKEY_CLASSES_ROOT = unchecked((int)0x80000000);
public static readonly HKEY HKEY_CURRENT_USER = unchecked((int)0x80000001);
public static readonly HKEY HKEY_LOCAL_MACHINE = unchecked((int)0x80000002);
public static readonly HKEY HKEY_USERS = unchecked((int)0x80000003);
public static readonly HKEY HKEY_CURRENT_CONFIG = unchecked((int)0x80000005);
public readonly nint Value;
public static unsafe implicit operator HKEY(int value) => *(HKEY*)&value;
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32.Registry;
[Flags]
internal enum REG_NOTIFY_FILTER : uint
{
REG_NOTIFY_CHANGE_NAME = 1u,
REG_NOTIFY_CHANGE_ATTRIBUTES = 2u,
REG_NOTIFY_CHANGE_LAST_SET = 4u,
REG_NOTIFY_CHANGE_SECURITY = 8u,
[SupportedOSPlatform("windows8.0")]
REG_NOTIFY_THREAD_AGNOSTIC = 0x10000000u,
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.Registry;
[Flags]
internal enum REG_SAM_FLAGS : uint
{
KEY_QUERY_VALUE = 1u,
KEY_SET_VALUE = 2u,
KEY_CREATE_SUB_KEY = 4u,
KEY_ENUMERATE_SUB_KEYS = 8u,
KEY_NOTIFY = 0x10u,
KEY_CREATE_LINK = 0x20u,
KEY_WOW64_32KEY = 0x200u,
KEY_WOW64_64KEY = 0x100u,
KEY_WOW64_RES = 0x300u,
KEY_READ = 0x20019u,
KEY_WRITE = 0x20006u,
KEY_EXECUTE = 0x20019u,
KEY_ALL_ACCESS = 0xF003Fu,
}

View File

@@ -1,10 +1,10 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using System.Runtime.InteropServices;
using Windows.Win32.Foundation;
using Windows.Win32.System.Registry;
using static Windows.Win32.PInvoke;
using static Snap.Hutao.Win32.AdvApi32;
using static Snap.Hutao.Win32.Macros;
namespace Snap.Hutao.Win32.Registry;
@@ -41,7 +41,7 @@ internal sealed partial class RegistryWatcher : IDisposable
nameof(HKEY.HKEY_LOCAL_MACHINE) => HKEY.HKEY_LOCAL_MACHINE,
nameof(HKEY.HKEY_USERS) => HKEY.HKEY_USERS,
nameof(HKEY.HKEY_CURRENT_CONFIG) => HKEY.HKEY_CURRENT_CONFIG,
_ => throw new ArgumentException("The registry hive '" + pathArray[0] + "' is not supported", nameof(keyName)),
_ => throw new ArgumentException($"The registry hive '{pathArray[0]}' is not supported", nameof(keyName)),
};
subKey = string.Join("\\", pathArray[1..]);
@@ -87,23 +87,6 @@ internal sealed partial class RegistryWatcher : IDisposable
}
}
[SuppressMessage("", "SH002")]
private static unsafe void UnsafeRegOpenKeyEx(HKEY hKey, string subKey, uint ulOptions, REG_SAM_FLAGS samDesired, out HKEY result)
{
fixed (HKEY* resultPtr = &result)
{
HRESULT hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(hKey, subKey, ulOptions, samDesired, resultPtr));
Marshal.ThrowExceptionForHR(hResult);
}
}
[SuppressMessage("", "SH002")]
private static unsafe void UnsafeRegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, REG_NOTIFY_FILTER dwNotifyFilter, HANDLE hEvent, BOOL fAsynchronous)
{
HRESULT hRESULT = HRESULT_FROM_WIN32(RegNotifyChangeKeyValue(hKey, bWatchSubtree, dwNotifyFilter, hEvent, fAsynchronous));
Marshal.ThrowExceptionForHR(hRESULT);
}
private async ValueTask WatchAsync(CancellationToken token)
{
try
@@ -112,7 +95,8 @@ internal sealed partial class RegistryWatcher : IDisposable
{
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
UnsafeRegOpenKeyEx(hKey, subKey, 0, RegSamFlags, out HKEY registryKey);
HRESULT hResult = HRESULT_FROM_WIN32(RegOpenKeyExW(hKey, subKey, 0, RegSamFlags, out HKEY registryKey));
Marshal.ThrowExceptionForHR(hResult);
using (ManualResetEvent notifyEvent = new(false))
{
@@ -126,7 +110,8 @@ internal sealed partial class RegistryWatcher : IDisposable
// skip both loops and exit the method.
while (!disposeEvent.WaitOne(0, true))
{
UnsafeRegNotifyChangeKeyValue(registryKey, true, RegNotifyFilters, hEvent, true);
HRESULT hRESULT = HRESULT_FROM_WIN32(RegNotifyChangeKeyValue(registryKey, true, RegNotifyFilters, hEvent, true));
Marshal.ThrowExceptionForHR(hRESULT);
if (WaitHandle.WaitAny([notifyEvent, disposeEvent]) is 0)
{

View File

@@ -0,0 +1,14 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.Security;
[SuppressMessage("", "SA1307")]
internal struct SECURITY_ATTRIBUTES
{
public uint nLength;
public unsafe void* lpSecurityDescriptor;
public BOOL bInheritHandle;
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.System.Com;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Snap.Hutao.Win32;
internal static class Shell32
{
[DllImport("SHELL32.dll", ExactSpelling = true)]
[SupportedOSPlatform("windows6.0.6000")]
public static unsafe extern HRESULT SHCreateItemFromParsingName(PCWSTR pszPath, [AllowNull] IBindCtx pbc, Guid* riid, void** ppv);
public static unsafe HRESULT SHCreateItemFromParsingName<T>(ReadOnlySpan<char> szPath, [AllowNull] IBindCtx pbc, ref readonly Guid riid, out T* pv)
where T : unmanaged
{
fixed (char* pszPath = szPath)
{
fixed (Guid* pGuid = &riid)
{
fixed (T** ppv = &pv)
{
return SHCreateItemFromParsingName(pszPath, pbc, pGuid, (void**)ppv);
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.Storage.FileSystem;
[SuppressMessage("", "SA1307")]
internal struct WIN32_FIND_DATAW
{
public uint dwFileAttributes;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public uint nFileSizeHigh;
public uint nFileSizeLow;
public uint dwReserved0;
public uint dwReserved1;
public unsafe fixed char cFileName[260];
public unsafe fixed char cAlternateFileName[14];
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Com;
[SuppressMessage("", "SA1307")]
internal struct BIND_OPTS
{
public uint cbStruct;
public uint grfFlags;
public uint grfMode;
public uint dwTickCountDeadline;
}

View File

@@ -0,0 +1,39 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Com;
[Flags]
internal enum CLSCTX : uint
{
CLSCTX_INPROC_SERVER = 1u,
CLSCTX_INPROC_HANDLER = 2u,
CLSCTX_LOCAL_SERVER = 4u,
CLSCTX_INPROC_SERVER16 = 8u,
CLSCTX_REMOTE_SERVER = 0x10u,
CLSCTX_INPROC_HANDLER16 = 0x20u,
CLSCTX_RESERVED1 = 0x40u,
CLSCTX_RESERVED2 = 0x80u,
CLSCTX_RESERVED3 = 0x100u,
CLSCTX_RESERVED4 = 0x200u,
CLSCTX_NO_CODE_DOWNLOAD = 0x400u,
CLSCTX_RESERVED5 = 0x800u,
CLSCTX_NO_CUSTOM_MARSHAL = 0x1000u,
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000u,
CLSCTX_NO_FAILURE_LOG = 0x4000u,
CLSCTX_DISABLE_AAA = 0x8000u,
CLSCTX_ENABLE_AAA = 0x10000u,
CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000u,
CLSCTX_ACTIVATE_X86_SERVER = 0x40000u,
CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000u,
CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000u,
CLSCTX_ENABLE_CLOAKING = 0x100000u,
CLSCTX_APPCONTAINER = 0x400000u,
CLSCTX_ACTIVATE_AAA_AS_IU = 0x800000u,
CLSCTX_RESERVED6 = 0x1000000u,
CLSCTX_ACTIVATE_ARM32_SERVER = 0x2000000u,
CLSCTX_ALLOW_LOWER_TRUST_REGISTRATION = 0x4000000u,
CLSCTX_PS_DLL = 0x80000000u,
CLSCTX_ALL = 0x17u,
CLSCTX_SERVER = 0x15u,
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Com;
[Flags]
internal enum CWMO_FLAGS
{
CWMO_DEFAULT = 0,
CWMO_DISPATCH_CALLS = 1,
CWMO_DISPATCH_WINDOW_MESSAGES = 2,
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IBindCtx
{
internal static Guid IID = new(14u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, IUnknown*, HRESULT> RegisterObjectBound;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, IUnknown*, HRESULT> RevokeObjectBound;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, HRESULT> ReleaseBoundObjects;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, BIND_OPTS*, HRESULT> SetBindOptions;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, BIND_OPTS*, HRESULT> GetBindOptions;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, IRunningObjectTable**, HRESULT> GetRunningObjectTable;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, PWSTR, IUnknown*, HRESULT> RegisterObjectParam;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, PWSTR, IUnknown**, HRESULT> GetObjectParam;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, IEnumString**, HRESULT> EnumObjectParam;
internal readonly delegate* unmanaged[Stdcall]<IBindCtx*, PWSTR, HRESULT> RevokeObjectParam;
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IEnumMoniker
{
internal static Guid IID = new(258u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;
internal readonly delegate* unmanaged[Stdcall]<IEnumMoniker*, uint, IMoniker**, uint*, HRESULT> Next;
internal readonly delegate* unmanaged[Stdcall]<IEnumMoniker*, uint, HRESULT> Skip;
internal readonly delegate* unmanaged[Stdcall]<IEnumMoniker*, HRESULT> Reset;
internal readonly delegate* unmanaged[Stdcall]<IEnumMoniker*, IEnumMoniker**, HRESULT> Clone;
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IEnumString
{
internal static Guid IID = new(257u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;
internal readonly delegate* unmanaged[Stdcall]<IEnumString*, uint, PWSTR*, uint*, HRESULT> Next;
internal readonly delegate* unmanaged[Stdcall]<IEnumString*, uint, HRESULT> Skip;
internal readonly delegate* unmanaged[Stdcall]<IEnumString*, HRESULT> Reset;
internal readonly delegate* unmanaged[Stdcall]<IEnumString*, IEnumString**, HRESULT> Clone;
}
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IMoniker
{
internal static Guid IID = new(15u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IPersistStream.Vftbl IPersistStreamVftbl;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, IMoniker*, Guid*, void**, HRESULT> BindToObject;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, IMoniker*, Guid*, void**, HRESULT> BindToStorage;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, uint, IMoniker**, IMoniker**, HRESULT> Reduce;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IMoniker*, BOOL, IMoniker**, HRESULT> ComposeWith;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, BOOL, IEnumMoniker**, HRESULT> Enum;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IMoniker*, HRESULT> IsEqual;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, uint*, HRESULT> Hash;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, IMoniker*, IMoniker*, HRESULT> IsRunning;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, IMoniker*, FILETIME*, HRESULT> GetTimeOfLastChange;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IMoniker**, HRESULT> Inverse;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IMoniker*, IMoniker**, HRESULT> CommonPrefixWith;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IMoniker*, IMoniker**, HRESULT> RelativePathTo;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, IMoniker*, PWSTR*, HRESULT> GetDisplayName;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, IBindCtx*, IMoniker*, PWSTR, uint*, IMoniker**, HRESULT> ParseDisplayName;
internal readonly delegate* unmanaged[Stdcall]<IMoniker*, uint*, HRESULT> IsSystemMoniker;
}
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IPersist
{
internal static readonly Guid IID = new(268u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal unsafe readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;
internal readonly delegate* unmanaged[Stdcall]<IPersist*, Guid*, HRESULT> GetClassID;
}
}

View File

@@ -0,0 +1,54 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using System.Runtime.CompilerServices;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IPersistFile
{
internal static Guid IID = new(267u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
public unsafe HRESULT QueryInterface<TInterface>(ref readonly Guid riid, out TInterface pvObject)
where TInterface : unmanaged
{
fixed (Guid* riid2 = &riid)
{
fixed (TInterface* ppvObject = &pvObject)
{
return thisPtr->IPersistVftbl.IUnknownVftbl.QueryInterface((IUnknown*)Unsafe.AsPointer(ref this), riid2, (void**)ppvObject);
}
}
}
public uint AddRef()
{
return thisPtr->IPersistVftbl.IUnknownVftbl.AddRef((IUnknown*)Unsafe.AsPointer(ref this));
}
public uint Release()
{
return thisPtr->IPersistVftbl.IUnknownVftbl.Release((IUnknown*)Unsafe.AsPointer(ref this));
}
public HRESULT Save(string szFileName, bool fRemember)
{
fixed (char* pszFileName = szFileName)
{
return thisPtr->Save((IPersistFile*)Unsafe.AsPointer(ref this), pszFileName, fRemember);
}
}
internal unsafe readonly struct Vftbl
{
internal readonly IPersist.Vftbl IPersistVftbl;
internal readonly delegate* unmanaged[Stdcall]<IPersistFile*, HRESULT> IsDirty;
internal readonly delegate* unmanaged[Stdcall]<IPersistFile*, PCWSTR, STGM, HRESULT> Load;
internal readonly delegate* unmanaged[Stdcall]<IPersistFile*, PCWSTR, BOOL, HRESULT> Save;
internal readonly delegate* unmanaged[Stdcall]<IPersistFile*, PCWSTR, HRESULT> SaveCompleted;
internal readonly delegate* unmanaged[Stdcall]<IPersistFile*, PWSTR*, HRESULT> GetCurFile;
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IPersistStream
{
internal static Guid IID = new(265u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IPersist.Vftbl IPersistVftbl;
internal readonly delegate* unmanaged[Stdcall]<IPersistStream*, HRESULT> IsDirty;
internal readonly delegate* unmanaged[Stdcall]<IPersistStream*, IStream*, HRESULT> Load;
internal readonly delegate* unmanaged[Stdcall]<IPersistStream*, IStream*, BOOL, HRESULT> Save;
internal readonly delegate* unmanaged[Stdcall]<IPersistStream*, ulong*, HRESULT> GetSizeMax;
}
}

View File

@@ -0,0 +1,29 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IRunningObjectTable
{
internal static Guid IID = new(16u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, ROT_FLAGS, IUnknown*, IMoniker*, uint*, HRESULT> Register;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, uint, HRESULT> Revoke;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, IMoniker*, HRESULT> IsRunning;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, IMoniker*, IUnknown**, HRESULT> GetObject;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, uint, FILETIME*, HRESULT> NoteChangeTime;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, IMoniker*, FILETIME*, HRESULT> GetTimeOfLastChange;
internal readonly delegate* unmanaged[Stdcall]<IRunningObjectTable*, IEnumMoniker**, HRESULT> EnumRunning;
}
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct ISequentialStream
{
internal static Guid IID = new(208878128u, 10780, 4558, 173, 229, 0, 170, 0, 68, 119, 61);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;
internal readonly delegate* unmanaged[Stdcall]<ISequentialStream*, void*, uint, uint*, HRESULT> Read;
internal readonly delegate* unmanaged[Stdcall]<ISequentialStream*, void*, uint, uint*, HRESULT> Write;
}
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IStream
{
internal static Guid IID = new(12u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
internal readonly struct Vftbl
{
internal readonly ISequentialStream.Vftbl ISequentialStreamVftbl;
internal readonly delegate* unmanaged[Stdcall]<IStream*, long, STREAM_SEEK, ulong*, HRESULT> Seek;
internal readonly delegate* unmanaged[Stdcall]<IStream*, ulong, HRESULT> SetSize;
internal readonly delegate* unmanaged[Stdcall]<IStream*, IStream*, ulong, ulong*, ulong*, HRESULT> CopyTo;
internal readonly delegate* unmanaged[Stdcall]<IStream*, uint, HRESULT> Commit;
internal readonly delegate* unmanaged[Stdcall]<IStream*, HRESULT> Revert;
internal readonly delegate* unmanaged[Stdcall]<IStream*, ulong, ulong, uint, HRESULT> LockRegion;
internal readonly delegate* unmanaged[Stdcall]<IStream*, ulong, ulong, uint, HRESULT> UnlockRegion;
internal readonly delegate* unmanaged[Stdcall]<IStream*, STATSTG*, uint, HRESULT> Stat;
internal readonly delegate* unmanaged[Stdcall]<IStream*, IStream**, HRESULT> Clone;
}
}

View File

@@ -0,0 +1,43 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using System.Runtime.CompilerServices;
namespace Snap.Hutao.Win32.System.Com;
internal unsafe struct IUnknown
{
internal static Guid IID = new(0u, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
private Vftbl* thisPtr;
public unsafe HRESULT QueryInterface<TInterface>(ref readonly Guid riid, out TInterface* pvObject)
where TInterface : unmanaged
{
fixed (Guid* riid2 = &riid)
{
fixed (TInterface** ppvObject = &pvObject)
{
return thisPtr->QueryInterface((IUnknown*)Unsafe.AsPointer(ref this), riid2, (void**)ppvObject);
}
}
}
public uint AddRef()
{
return thisPtr->AddRef((IUnknown*)Unsafe.AsPointer(ref this));
}
public uint Release()
{
return thisPtr->Release((IUnknown*)Unsafe.AsPointer(ref this));
}
internal unsafe readonly struct Vftbl
{
internal readonly delegate* unmanaged[Stdcall]<IUnknown*, Guid*, void**, HRESULT> QueryInterface;
internal readonly delegate* unmanaged[Stdcall]<IUnknown*, uint> AddRef;
internal readonly delegate* unmanaged[Stdcall]<IUnknown*, uint> Release;
}
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Com;
[Flags]
internal enum ROT_FLAGS : uint
{
ROTFLAGS_REGISTRATIONKEEPSALIVE = 1u,
ROTFLAGS_ALLOWANYCLIENT = 2u,
}

View File

@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.Com;
// [StructSizeField("cbSize")]
[SuppressMessage("", "SA1307")]
internal struct STATSTG
{
public PWSTR pwcsName;
public uint type;
public ulong cbSize;
public FILETIME mtime;
public FILETIME ctime;
public FILETIME atime;
public STGM grfMode;
// [AssociatedEnum("LOCKTYPE")]
public uint grfLocksSupported;
public Guid clsid;
public uint grfStateBits;
public uint reserved;
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Com;
internal enum STGM : uint
{
STGM_DIRECT = 0u,
STGM_TRANSACTED = 0x10000u,
STGM_SIMPLE = 0x8000000u,
STGM_READ = 0u,
STGM_WRITE = 1u,
STGM_READWRITE = 2u,
STGM_SHARE_DENY_NONE = 0x40u,
STGM_SHARE_DENY_READ = 0x30u,
STGM_SHARE_DENY_WRITE = 0x20u,
STGM_SHARE_EXCLUSIVE = 0x10u,
STGM_PRIORITY = 0x40000u,
STGM_DELETEONRELEASE = 0x4000000u,
STGM_NOSCRATCH = 0x100000u,
STGM_CREATE = 0x1000u,
STGM_CONVERT = 0x20000u,
STGM_FAILIFTHERE = 0u,
STGM_NOSNAPSHOT = 0x200000u,
STGM_DIRECT_SWMR = 0x400000u,
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Com;
internal enum STREAM_SEEK : uint
{
STREAM_SEEK_SET,
STREAM_SEEK_CUR,
STREAM_SEEK_END,
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Console;
[Flags]
internal enum CONSOLE_MODE : uint
{
ENABLE_PROCESSED_INPUT = 0x001U,
ENABLE_LINE_INPUT = 0x002U,
ENABLE_ECHO_INPUT = 0x004U,
ENABLE_WINDOW_INPUT = 0x008U,
ENABLE_MOUSE_INPUT = 0x010U,
ENABLE_INSERT_MODE = 0x020U,
ENABLE_QUICK_EDIT_MODE = 0x040U,
ENABLE_EXTENDED_FLAGS = 0x080U,
ENABLE_AUTO_POSITION = 0x100U,
ENABLE_VIRTUAL_TERMINAL_INPUT = 0x200U,
ENABLE_PROCESSED_OUTPUT = 0x01U,
ENABLE_WRAP_AT_EOL_OUTPUT = 0x02U,
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x04U,
DISABLE_NEWLINE_AUTO_RETURN = 0x08U,
ENABLE_LVB_GRID_WORLDWIDE = 0x10U,
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Console;
internal enum STD_HANDLE : uint
{
STD_INPUT_HANDLE = 0xFFFFFFF6U,
STD_OUTPUT_HANDLE = 0xFFFFFFF5U,
STD_ERROR_HANDLE = 0xFFFFFFF4U,
}

View File

@@ -0,0 +1,161 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
internal enum FACILITY_CODE : uint
{
FACILITY_NULL = 0u,
FACILITY_RPC = 1u,
FACILITY_DISPATCH = 2u,
FACILITY_STORAGE = 3u,
FACILITY_ITF = 4u,
FACILITY_WIN32 = 7u,
FACILITY_WINDOWS = 8u,
FACILITY_SSPI = 9u,
FACILITY_SECURITY = 9u,
FACILITY_CONTROL = 10u,
FACILITY_CERT = 11u,
FACILITY_INTERNET = 12u,
FACILITY_MEDIASERVER = 13u,
FACILITY_MSMQ = 14u,
FACILITY_SETUPAPI = 15u,
FACILITY_SCARD = 16u,
FACILITY_COMPLUS = 17u,
FACILITY_AAF = 18u,
FACILITY_URT = 19u,
FACILITY_ACS = 20u,
FACILITY_DPLAY = 21u,
FACILITY_UMI = 22u,
FACILITY_SXS = 23u,
FACILITY_WINDOWS_CE = 24u,
FACILITY_HTTP = 25u,
FACILITY_USERMODE_COMMONLOG = 26u,
FACILITY_WER = 27u,
FACILITY_USERMODE_FILTER_MANAGER = 31u,
FACILITY_BACKGROUNDCOPY = 32u,
FACILITY_CONFIGURATION = 33u,
FACILITY_WIA = 33u,
FACILITY_STATE_MANAGEMENT = 34u,
FACILITY_METADIRECTORY = 35u,
FACILITY_WINDOWSUPDATE = 36u,
FACILITY_DIRECTORYSERVICE = 37u,
FACILITY_GRAPHICS = 38u,
FACILITY_SHELL = 39u,
FACILITY_NAP = 39u,
FACILITY_TPM_SERVICES = 40u,
FACILITY_TPM_SOFTWARE = 41u,
FACILITY_UI = 42u,
FACILITY_XAML = 43u,
FACILITY_ACTION_QUEUE = 44u,
FACILITY_PLA = 48u,
FACILITY_WINDOWS_SETUP = 48u,
FACILITY_FVE = 49u,
FACILITY_FWP = 50u,
FACILITY_WINRM = 51u,
FACILITY_NDIS = 52u,
FACILITY_USERMODE_HYPERVISOR = 53u,
FACILITY_CMI = 54u,
FACILITY_USERMODE_VIRTUALIZATION = 55u,
FACILITY_USERMODE_VOLMGR = 56u,
FACILITY_BCD = 57u,
FACILITY_USERMODE_VHD = 58u,
FACILITY_USERMODE_HNS = 59u,
FACILITY_SDIAG = 60u,
FACILITY_WEBSERVICES = 61u,
FACILITY_WINPE = 61u,
FACILITY_WPN = 62u,
FACILITY_WINDOWS_STORE = 63u,
FACILITY_INPUT = 64u,
FACILITY_QUIC = 65u,
FACILITY_EAP = 66u,
FACILITY_IORING = 70u,
FACILITY_WINDOWS_DEFENDER = 80u,
FACILITY_OPC = 81u,
FACILITY_XPS = 82u,
FACILITY_MBN = 84u,
FACILITY_POWERSHELL = 84u,
FACILITY_RAS = 83u,
FACILITY_P2P_INT = 98u,
FACILITY_P2P = 99u,
FACILITY_DAF = 100u,
FACILITY_BLUETOOTH_ATT = 101u,
FACILITY_AUDIO = 102u,
FACILITY_STATEREPOSITORY = 103u,
FACILITY_VISUALCPP = 109u,
FACILITY_SCRIPT = 112u,
FACILITY_PARSE = 113u,
FACILITY_BLB = 120u,
FACILITY_BLB_CLI = 121u,
FACILITY_WSBAPP = 122u,
FACILITY_BLBUI = 128u,
FACILITY_USN = 129u,
FACILITY_USERMODE_VOLSNAP = 130u,
FACILITY_TIERING = 131u,
FACILITY_WSB_ONLINE = 133u,
FACILITY_ONLINE_ID = 134u,
FACILITY_DEVICE_UPDATE_AGENT = 135u,
FACILITY_DRVSERVICING = 136u,
FACILITY_DLS = 153u,
FACILITY_DELIVERY_OPTIMIZATION = 208u,
FACILITY_USERMODE_SPACES = 231u,
FACILITY_USER_MODE_SECURITY_CORE = 232u,
FACILITY_USERMODE_LICENSING = 234u,
FACILITY_SOS = 160u,
FACILITY_OCP_UPDATE_AGENT = 173u,
FACILITY_DEBUGGERS = 176u,
FACILITY_SPP = 256u,
FACILITY_RESTORE = 256u,
FACILITY_DMSERVER = 256u,
FACILITY_DEPLOYMENT_SERVICES_SERVER = 257u,
FACILITY_DEPLOYMENT_SERVICES_IMAGING = 258u,
FACILITY_DEPLOYMENT_SERVICES_MANAGEMENT = 259u,
FACILITY_DEPLOYMENT_SERVICES_UTIL = 260u,
FACILITY_DEPLOYMENT_SERVICES_BINLSVC = 261u,
FACILITY_DEPLOYMENT_SERVICES_PXE = 263u,
FACILITY_DEPLOYMENT_SERVICES_TFTP = 264u,
FACILITY_DEPLOYMENT_SERVICES_TRANSPORT_MANAGEMENT = 272u,
FACILITY_DEPLOYMENT_SERVICES_DRIVER_PROVISIONING = 278u,
FACILITY_DEPLOYMENT_SERVICES_MULTICAST_SERVER = 289u,
FACILITY_DEPLOYMENT_SERVICES_MULTICAST_CLIENT = 290u,
FACILITY_DEPLOYMENT_SERVICES_CONTENT_PROVIDER = 293u,
FACILITY_HSP_SERVICES = 296u,
FACILITY_HSP_SOFTWARE = 297u,
FACILITY_LINGUISTIC_SERVICES = 305u,
FACILITY_AUDIOSTREAMING = 1094u,
FACILITY_TTD = 1490u,
FACILITY_ACCELERATOR = 1536u,
FACILITY_WMAAECMA = 1996u,
FACILITY_DIRECTMUSIC = 2168u,
FACILITY_DIRECT3D10 = 2169u,
FACILITY_DXGI = 2170u,
FACILITY_DXGI_DDI = 2171u,
FACILITY_DIRECT3D11 = 2172u,
FACILITY_DIRECT3D11_DEBUG = 2173u,
FACILITY_DIRECT3D12 = 2174u,
FACILITY_DIRECT3D12_DEBUG = 2175u,
FACILITY_DXCORE = 2176u,
FACILITY_PRESENTATION = 2177u,
FACILITY_LEAP = 2184u,
FACILITY_AUDCLNT = 2185u,
FACILITY_WINCODEC_DWRITE_DWM = 2200u,
FACILITY_WINML = 2192u,
FACILITY_DIRECT2D = 2201u,
FACILITY_DEFRAG = 2304u,
FACILITY_USERMODE_SDBUS = 2305u,
FACILITY_JSCRIPT = 2306u,
FACILITY_PIDGENX = 2561u,
FACILITY_EAS = 85u,
FACILITY_WEB = 885u,
FACILITY_WEB_SOCKET = 886u,
FACILITY_MOBILE = 1793u,
FACILITY_SQLITE = 1967u,
FACILITY_SERVICE_FABRIC = 1968u,
FACILITY_UTC = 1989u,
FACILITY_WEP = 2049u,
FACILITY_SYNCENGINE = 2050u,
FACILITY_XBOX = 2339u,
FACILITY_GAME = 2340u,
FACILITY_PIX = 2748u,
FACILITY_NT_BIT = 268435456u,
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.ProcessStatus;
[SuppressMessage("", "SA1307")]
internal struct MODULEINFO
{
public unsafe void* lpBaseOfDll;
public uint SizeOfImage;
public unsafe void* EntryPoint;
}

View File

@@ -0,0 +1,45 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.System.SystemServices;
[Flags]
internal enum SFGAO_FLAGS : uint
{
SFGAO_CANCOPY = 1u,
SFGAO_CANMOVE = 2u,
SFGAO_CANLINK = 4u,
SFGAO_STORAGE = 8u,
SFGAO_CANRENAME = 0x10u,
SFGAO_CANDELETE = 0x20u,
SFGAO_HASPROPSHEET = 0x40u,
SFGAO_DROPTARGET = 0x100u,
SFGAO_CAPABILITYMASK = 0x177u,
SFGAO_PLACEHOLDER = 0x800u,
SFGAO_SYSTEM = 0x1000u,
SFGAO_ENCRYPTED = 0x2000u,
SFGAO_ISSLOW = 0x4000u,
SFGAO_GHOSTED = 0x8000u,
SFGAO_LINK = 0x10000u,
SFGAO_SHARE = 0x20000u,
SFGAO_READONLY = 0x40000u,
SFGAO_HIDDEN = 0x80000u,
SFGAO_DISPLAYATTRMASK = 0xFC000u,
SFGAO_FILESYSANCESTOR = 0x10000000u,
SFGAO_FOLDER = 0x20000000u,
SFGAO_FILESYSTEM = 0x40000000u,
SFGAO_HASSUBFOLDER = 0x80000000u,
SFGAO_CONTENTSMASK = 0x80000000u,
SFGAO_VALIDATE = 0x1000000u,
SFGAO_REMOVABLE = 0x2000000u,
SFGAO_COMPRESSED = 0x4000000u,
SFGAO_BROWSABLE = 0x8000000u,
SFGAO_NONENUMERATED = 0x100000u,
SFGAO_NEWCONTENT = 0x200000u,
SFGAO_CANMONIKER = 0x400000u,
SFGAO_HASSTORAGE = 0x400000u,
SFGAO_STREAM = 0x400000u,
SFGAO_STORAGEANCESTOR = 0x800000u,
SFGAO_STORAGECAPMASK = 0x70C50008u,
SFGAO_PKEYSFGAOMASK = 0x81044000u,
}

View File

@@ -0,0 +1,16 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
using System.Runtime.InteropServices;
namespace Snap.Hutao.Win32.System.WinRT;
[ComImport]
[Guid("5B0D3235-4DBA-4D44-865E-8F1D0E4FD04D")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMemoryBufferByteAccess
{
[PreserveSig]
unsafe HRESULT GetBuffer(byte** value, uint* capacity);
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.System.WinRT;
internal static class IMemoryBufferByteAccessExtension
{
public static unsafe HRESULT GetBuffer(this IMemoryBufferByteAccess memoryBufferByteAccess, out byte* value, out uint capacity)
{
fixed (byte** value2 = &value)
{
fixed (uint* capacity2 = &capacity)
{
return memoryBufferByteAccess.GetBuffer(value2, capacity2);
}
}
}
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[SuppressMessage("", "SA1307")]
internal struct HARDWAREINPUT
{
public uint uMsg;
public ushort wParamL;
public ushort wParamH;
}

View File

@@ -0,0 +1,14 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[Flags]
internal enum HOT_KEY_MODIFIERS : uint
{
MOD_ALT = 1u,
MOD_CONTROL = 2u,
MOD_NOREPEAT = 0x4000u,
MOD_SHIFT = 4u,
MOD_WIN = 8u,
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.InteropServices;
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[SuppressMessage("", "SA1307")]
internal struct INPUT
{
public INPUT_TYPE type;
public AnonymousUnion Anonymous;
[StructLayout(LayoutKind.Explicit)]
public struct AnonymousUnion
{
[FieldOffset(0)]
public MOUSEINPUT mi;
[FieldOffset(0)]
public KEYBDINPUT ki;
[FieldOffset(0)]
public HARDWAREINPUT hi;
}
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
internal enum INPUT_TYPE : uint
{
INPUT_MOUSE,
INPUT_KEYBOARD,
INPUT_HARDWARE,
}

View File

@@ -0,0 +1,14 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[SuppressMessage("", "SA1307")]
internal struct KEYBDINPUT
{
public VIRTUAL_KEY wVk;
public ushort wScan;
public KEYBD_EVENT_FLAGS dwFlags;
public uint time;
public nuint dwExtraInfo;
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[Flags]
internal enum KEYBD_EVENT_FLAGS : uint
{
KEYEVENTF_EXTENDEDKEY = 1u,
KEYEVENTF_KEYUP = 2u,
KEYEVENTF_SCANCODE = 8u,
KEYEVENTF_UNICODE = 4u,
}

View File

@@ -0,0 +1,15 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[SuppressMessage("", "SA1307")]
internal struct MOUSEINPUT
{
public int dx;
public int dy;
public uint mouseData;
public MOUSE_EVENT_FLAGS dwFlags;
public uint time;
public nuint dwExtraInfo;
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
[Flags]
internal enum MOUSE_EVENT_FLAGS : uint
{
MOUSEEVENTF_ABSOLUTE = 0x8000u,
MOUSEEVENTF_LEFTDOWN = 2u,
MOUSEEVENTF_LEFTUP = 4u,
MOUSEEVENTF_MIDDLEDOWN = 0x20u,
MOUSEEVENTF_MIDDLEUP = 0x40u,
MOUSEEVENTF_MOVE = 1u,
MOUSEEVENTF_RIGHTDOWN = 8u,
MOUSEEVENTF_RIGHTUP = 0x10u,
MOUSEEVENTF_WHEEL = 0x800u,
MOUSEEVENTF_XDOWN = 0x80u,
MOUSEEVENTF_XUP = 0x100u,
MOUSEEVENTF_HWHEEL = 0x1000u,
MOUSEEVENTF_MOVE_NOCOALESCE = 0x2000u,
MOUSEEVENTF_VIRTUALDESK = 0x4000u,
}

View File

@@ -0,0 +1,255 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
internal enum VIRTUAL_KEY : ushort
{
VK_0 = 48,
VK_1 = 49,
VK_2 = 50,
VK_3 = 51,
VK_4 = 52,
VK_5 = 53,
VK_6 = 54,
VK_7 = 55,
VK_8 = 56,
VK_9 = 57,
VK_A = 65,
VK_B = 66,
VK_C = 67,
VK_D = 68,
VK_E = 69,
VK_F = 70,
VK_G = 71,
VK_H = 72,
VK_I = 73,
VK_J = 74,
VK_K = 75,
VK_L = 76,
VK_M = 77,
VK_N = 78,
VK_O = 79,
VK_P = 80,
VK_Q = 81,
VK_R = 82,
VK_S = 83,
VK_T = 84,
VK_U = 85,
VK_V = 86,
VK_W = 87,
VK_X = 88,
VK_Y = 89,
VK_Z = 90,
VK_ABNT_C1 = 193,
VK_ABNT_C2 = 194,
VK_DBE_ALPHANUMERIC = 240,
VK_DBE_CODEINPUT = 250,
VK_DBE_DBCSCHAR = 244,
VK_DBE_DETERMINESTRING = 252,
VK_DBE_ENTERDLGCONVERSIONMODE = 253,
VK_DBE_ENTERIMECONFIGMODE = 248,
VK_DBE_ENTERWORDREGISTERMODE = 247,
VK_DBE_FLUSHSTRING = 249,
VK_DBE_HIRAGANA = 242,
VK_DBE_KATAKANA = 241,
VK_DBE_NOCODEINPUT = 251,
VK_DBE_NOROMAN = 246,
VK_DBE_ROMAN = 245,
VK_DBE_SBCSCHAR = 243,
VK__none_ = 255,
VK_LBUTTON = 1,
VK_RBUTTON = 2,
VK_CANCEL = 3,
VK_MBUTTON = 4,
VK_XBUTTON1 = 5,
VK_XBUTTON2 = 6,
VK_BACK = 8,
VK_TAB = 9,
VK_CLEAR = 12,
VK_RETURN = 13,
VK_SHIFT = 16,
VK_CONTROL = 17,
VK_MENU = 18,
VK_PAUSE = 19,
VK_CAPITAL = 20,
VK_KANA = 21,
VK_HANGEUL = 21,
VK_HANGUL = 21,
VK_IME_ON = 22,
VK_JUNJA = 23,
VK_FINAL = 24,
VK_HANJA = 25,
VK_KANJI = 25,
VK_IME_OFF = 26,
VK_ESCAPE = 27,
VK_CONVERT = 28,
VK_NONCONVERT = 29,
VK_ACCEPT = 30,
VK_MODECHANGE = 31,
VK_SPACE = 32,
VK_PRIOR = 33,
VK_NEXT = 34,
VK_END = 35,
VK_HOME = 36,
VK_LEFT = 37,
VK_UP = 38,
VK_RIGHT = 39,
VK_DOWN = 40,
VK_SELECT = 41,
VK_PRINT = 42,
VK_EXECUTE = 43,
VK_SNAPSHOT = 44,
VK_INSERT = 45,
VK_DELETE = 46,
VK_HELP = 47,
VK_LWIN = 91,
VK_RWIN = 92,
VK_APPS = 93,
VK_SLEEP = 95,
VK_NUMPAD0 = 96,
VK_NUMPAD1 = 97,
VK_NUMPAD2 = 98,
VK_NUMPAD3 = 99,
VK_NUMPAD4 = 100,
VK_NUMPAD5 = 101,
VK_NUMPAD6 = 102,
VK_NUMPAD7 = 103,
VK_NUMPAD8 = 104,
VK_NUMPAD9 = 105,
VK_MULTIPLY = 106,
VK_ADD = 107,
VK_SEPARATOR = 108,
VK_SUBTRACT = 109,
VK_DECIMAL = 110,
VK_DIVIDE = 111,
VK_F1 = 112,
VK_F2 = 113,
VK_F3 = 114,
VK_F4 = 115,
VK_F5 = 116,
VK_F6 = 117,
VK_F7 = 118,
VK_F8 = 119,
VK_F9 = 120,
VK_F10 = 121,
VK_F11 = 122,
VK_F12 = 123,
VK_F13 = 124,
VK_F14 = 125,
VK_F15 = 126,
VK_F16 = 127,
VK_F17 = 128,
VK_F18 = 129,
VK_F19 = 130,
VK_F20 = 131,
VK_F21 = 132,
VK_F22 = 133,
VK_F23 = 134,
VK_F24 = 135,
VK_NAVIGATION_VIEW = 136,
VK_NAVIGATION_MENU = 137,
VK_NAVIGATION_UP = 138,
VK_NAVIGATION_DOWN = 139,
VK_NAVIGATION_LEFT = 140,
VK_NAVIGATION_RIGHT = 141,
VK_NAVIGATION_ACCEPT = 142,
VK_NAVIGATION_CANCEL = 143,
VK_NUMLOCK = 144,
VK_SCROLL = 145,
VK_OEM_NEC_EQUAL = 146,
VK_OEM_FJ_JISHO = 146,
VK_OEM_FJ_MASSHOU = 147,
VK_OEM_FJ_TOUROKU = 148,
VK_OEM_FJ_LOYA = 149,
VK_OEM_FJ_ROYA = 150,
VK_LSHIFT = 160,
VK_RSHIFT = 161,
VK_LCONTROL = 162,
VK_RCONTROL = 163,
VK_LMENU = 164,
VK_RMENU = 165,
VK_BROWSER_BACK = 166,
VK_BROWSER_FORWARD = 167,
VK_BROWSER_REFRESH = 168,
VK_BROWSER_STOP = 169,
VK_BROWSER_SEARCH = 170,
VK_BROWSER_FAVORITES = 171,
VK_BROWSER_HOME = 172,
VK_VOLUME_MUTE = 173,
VK_VOLUME_DOWN = 174,
VK_VOLUME_UP = 175,
VK_MEDIA_NEXT_TRACK = 176,
VK_MEDIA_PREV_TRACK = 177,
VK_MEDIA_STOP = 178,
VK_MEDIA_PLAY_PAUSE = 179,
VK_LAUNCH_MAIL = 180,
VK_LAUNCH_MEDIA_SELECT = 181,
VK_LAUNCH_APP1 = 182,
VK_LAUNCH_APP2 = 183,
VK_OEM_1 = 186,
VK_OEM_PLUS = 187,
VK_OEM_COMMA = 188,
VK_OEM_MINUS = 189,
VK_OEM_PERIOD = 190,
VK_OEM_2 = 191,
VK_OEM_3 = 192,
VK_GAMEPAD_A = 195,
VK_GAMEPAD_B = 196,
VK_GAMEPAD_X = 197,
VK_GAMEPAD_Y = 198,
VK_GAMEPAD_RIGHT_SHOULDER = 199,
VK_GAMEPAD_LEFT_SHOULDER = 200,
VK_GAMEPAD_LEFT_TRIGGER = 201,
VK_GAMEPAD_RIGHT_TRIGGER = 202,
VK_GAMEPAD_DPAD_UP = 203,
VK_GAMEPAD_DPAD_DOWN = 204,
VK_GAMEPAD_DPAD_LEFT = 205,
VK_GAMEPAD_DPAD_RIGHT = 206,
VK_GAMEPAD_MENU = 207,
VK_GAMEPAD_VIEW = 208,
VK_GAMEPAD_LEFT_THUMBSTICK_BUTTON = 209,
VK_GAMEPAD_RIGHT_THUMBSTICK_BUTTON = 210,
VK_GAMEPAD_LEFT_THUMBSTICK_UP = 211,
VK_GAMEPAD_LEFT_THUMBSTICK_DOWN = 212,
VK_GAMEPAD_LEFT_THUMBSTICK_RIGHT = 213,
VK_GAMEPAD_LEFT_THUMBSTICK_LEFT = 214,
VK_GAMEPAD_RIGHT_THUMBSTICK_UP = 215,
VK_GAMEPAD_RIGHT_THUMBSTICK_DOWN = 216,
VK_GAMEPAD_RIGHT_THUMBSTICK_RIGHT = 217,
VK_GAMEPAD_RIGHT_THUMBSTICK_LEFT = 218,
VK_OEM_4 = 219,
VK_OEM_5 = 220,
VK_OEM_6 = 221,
VK_OEM_7 = 222,
VK_OEM_8 = 223,
VK_OEM_AX = 225,
VK_OEM_102 = 226,
VK_ICO_HELP = 227,
VK_ICO_00 = 228,
VK_PROCESSKEY = 229,
VK_ICO_CLEAR = 230,
VK_PACKET = 231,
VK_OEM_RESET = 233,
VK_OEM_JUMP = 234,
VK_OEM_PA1 = 235,
VK_OEM_PA2 = 236,
VK_OEM_PA3 = 237,
VK_OEM_WSCTRL = 238,
VK_OEM_CUSEL = 239,
VK_OEM_ATTN = 240,
VK_OEM_FINISH = 241,
VK_OEM_COPY = 242,
VK_OEM_AUTO = 243,
VK_OEM_ENLW = 244,
VK_OEM_BACKTAB = 245,
VK_ATTN = 246,
VK_CRSEL = 247,
VK_EXSEL = 248,
VK_EREOF = 249,
VK_PLAY = 250,
VK_ZOOM = 251,
VK_NONAME = 252,
VK_PA1 = 253,
VK_OEM_CLEAR = 254,
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Win32.Foundation;
namespace Snap.Hutao.Win32.UI.Shell.Common;
[SuppressMessage("", "SA1307")]
internal struct COMDLG_FILTERSPEC
{
public PCWSTR pszName;
public PCWSTR pszSpec;
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.InteropServices;
namespace Snap.Hutao.Win32.UI.Shell.Common;
[SuppressMessage("", "SA1307")]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal readonly struct ITEMIDLIST
{
public readonly SHITEMID mkid;
}

View File

@@ -0,0 +1,14 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.InteropServices;
namespace Snap.Hutao.Win32.UI.Shell.Common;
[SuppressMessage("", "SA1307")]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct SHITEMID
{
public ushort cb;
public unsafe byte* abID;
}

View File

@@ -0,0 +1,10 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Win32.UI.Shell;
internal enum FDAP
{
FDAP_BOTTOM,
FDAP_TOP,
}

Some files were not shown because too many files have changed in this diff Show More