diff --git a/CoreAppUWP/Common/HookRegistry.cs b/CoreAppUWP/Common/HookRegistry.cs
index 05138c1..d3b6b82 100644
--- a/CoreAppUWP/Common/HookRegistry.cs
+++ b/CoreAppUWP/Common/HookRegistry.cs
@@ -9,30 +9,68 @@
namespace CoreAppUWP.Common
{
- public class HookRegistry : IDisposable
+ ///
+ /// Represents a hook for getting the value of the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WinUI\Xaml\EnableUWPWindow registry key always returning .
+ ///
+ public partial class HookRegistry : IDisposable
{
+ ///
+ /// The value that indicates whether the class has been disposed.
+ ///
private bool disposed;
+
+ ///
+ /// The reference count for the hook.
+ ///
private static int refCount;
+
+ ///
+ /// The dictionary that maps the to a value that indicates whether the key is a real key.
+ ///
private static readonly Dictionary xamlKeyMap = [];
+
+ ///
+ /// The object used to synchronize access to the dictionary.
+ ///
private static readonly object locker = new();
+ /// The original function.
+ ///
private static unsafe delegate* unmanaged[Stdcall] RegOpenKeyExW;
+
+ /// The original function.
+ ///
private static unsafe delegate* unmanaged[Stdcall] RegCloseKey;
+
+ /// The original function.
+ ///
private static unsafe delegate* unmanaged[Stdcall] RegQueryValueExW;
+ ///
+ /// Initializes a new instance of the class.
+ ///
public HookRegistry()
{
refCount++;
StartHook();
}
+ ///
+ /// Finalizes this instance of the class.
+ ///
~HookRegistry()
{
Dispose();
}
+ ///
+ /// Gets the value that indicates whether the hook is active.
+ ///
public static bool IsHooked { get; private set; }
+ ///
+ /// Starts the hook for the function.
+ ///
private static unsafe void StartHook()
{
if (!IsHooked)
@@ -69,6 +107,9 @@ private static unsafe void StartHook()
}
}
+ ///
+ /// Ends the hook for the function.
+ ///
public static unsafe void EndHook()
{
if (--refCount == 0 && IsHooked)
@@ -96,6 +137,8 @@ public static unsafe void EndHook()
}
}
+ /// The overridden function.
+ ///
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
private static unsafe WIN32_ERROR OverrideRegOpenKeyExW(HKEY hKey, PCWSTR lpSubKey, uint ulOptions, REG_SAM_FLAGS samDesired, HKEY* phkResult)
{
@@ -117,6 +160,8 @@ private static unsafe WIN32_ERROR OverrideRegOpenKeyExW(HKEY hKey, PCWSTR lpSubK
return result;
}
+ /// The overridden function.
+ ///
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
private static unsafe WIN32_ERROR OverrideRegCloseKey(HKEY hKey)
{
@@ -137,6 +182,8 @@ private static unsafe WIN32_ERROR OverrideRegCloseKey(HKEY hKey)
}
}
+ /// The overridden function.
+ ///
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
private static unsafe WIN32_ERROR OverrideRegQueryValueExW(HKEY hKey, PCWSTR lpValueName, [Optional] uint* lpReserved, [Optional] REG_VALUE_TYPE* lpType, [Optional] byte* lpData, [Optional] uint* lpcbData)
{
@@ -205,6 +252,7 @@ private static unsafe WIN32_ERROR OverrideRegQueryValueExW(HKEY hKey, PCWSTR lpV
return RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
}
+ ///
public void Dispose()
{
if (!disposed && IsHooked)
diff --git a/CoreAppUWP/Common/HookWindowingModel.cs b/CoreAppUWP/Common/HookWindowingModel.cs
index 4916b9f..1cc76c9 100644
--- a/CoreAppUWP/Common/HookWindowingModel.cs
+++ b/CoreAppUWP/Common/HookWindowingModel.cs
@@ -8,27 +8,60 @@
namespace CoreAppUWP.Common
{
- public sealed class HookWindowingModel : IDisposable
+ ///
+ /// Represents a hook for the function.
+ ///
+ public sealed partial class HookWindowingModel : IDisposable
{
+ ///
+ /// The value that indicates whether the class has been disposed.
+ ///
private bool disposed;
+
+ ///
+ /// The reference count for the hook.
+ ///
private static int refCount;
+
+ ///
+ /// The value that represents the current process token.
+ ///
private const int currentProcessToken = -6;
+
+ /// The original function.
+ ///
private static unsafe delegate* unmanaged[Stdcall] AppPolicyGetWindowingModel;
+ ///
+ /// Initializes a new instance of the class.
+ ///
public HookWindowingModel()
{
refCount++;
StartHook();
}
+ ///
+ /// Finalizes this instance of the class.
+ ///
~HookWindowingModel()
{
Dispose();
}
+ ///
+ /// Gets the value that indicates whether the hook is active.
+ ///
public static bool IsHooked { get; private set; }
+
+ ///
+ /// Gets or sets the windowing model to use when the hooked function is called.
+ ///
internal static AppPolicyWindowingModel WindowingModel { get; set; } = AppPolicyWindowingModel.AppPolicyWindowingModel_ClassicDesktop;
+ ///
+ /// Starts the hook for the function.
+ ///
private static unsafe void StartHook()
{
if (!IsHooked)
@@ -52,6 +85,9 @@ private static unsafe void StartHook()
}
}
+ ///
+ /// Ends the hook for the function.
+ ///
private static unsafe void EndHook()
{
if (--refCount == 0 && IsHooked)
@@ -69,6 +105,10 @@ private static unsafe void EndHook()
}
}
+ /// A pointer to a variable of the AppPolicyWindowingModel enumerated type.
+ /// When the function returns successfully, the variable contains the when the identified process is current; otherwise, the windowing model of the identified process.
+ /// The overridden function.
+ ///
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
private static unsafe WIN32_ERROR OverrideAppPolicyGetWindowingModel(HANDLE processToken, AppPolicyWindowingModel* policy)
{
@@ -80,6 +120,7 @@ private static unsafe WIN32_ERROR OverrideAppPolicyGetWindowingModel(HANDLE proc
return AppPolicyGetWindowingModel(processToken, policy);
}
+ ///
public void Dispose()
{
if (!disposed && IsHooked)
diff --git a/CoreAppUWP/CoreAppUWP.csproj b/CoreAppUWP/CoreAppUWP.csproj
index 1ebe1f3..64988b3 100644
--- a/CoreAppUWP/CoreAppUWP.csproj
+++ b/CoreAppUWP/CoreAppUWP.csproj
@@ -4,7 +4,7 @@
app.manifest
True
CoreAppUWP.WinRT
- DISABLE_XAML_GENERATED_MAIN
+ $(DefineConstants);DISABLE_XAML_GENERATED_MAIN
True
True
$(NoWarn);NU1902;NU1903;NU1904
@@ -31,8 +31,8 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
diff --git a/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs b/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs
index f75fa2d..96bbc63 100644
--- a/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs
+++ b/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs
@@ -19,7 +19,7 @@
namespace CoreAppUWP.ViewModels.SettingsPages
{
- public class SettingsViewModel : INotifyPropertyChanged
+ public partial class SettingsViewModel : INotifyPropertyChanged
{
public static ConditionalWeakTable Caches { get; } = [];
diff --git a/EnableUWPWindow.reg b/EnableUWPWindow.reg
index 845e4f9..d2a33aa 100644
Binary files a/EnableUWPWindow.reg and b/EnableUWPWindow.reg differ