From dfae40e49422069bd719b5b0e8d3a2f916fdf6c9 Mon Sep 17 00:00:00 2001 From: BH2WFR <60873943+BH2WFR@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:28:17 +0800 Subject: [PATCH] tried to add some functions (#113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fea #109, - add `CreateDXGIFactory2` in `dxgi,hpp` - add `InjectTouchInput` in `ext-ms-win-rtcore-ntuser-wmpointer.hpp` - add `InitializeTouchInjection` in `ext-ms-win-rtcore-ntuser-wmpointer.hpp` - add `GetCurrentPackageFullName` in `kernel32.hpp` * 修改 `CreateDXGIFactory2` 增加 `GetProcessDpiAwareness` , 文件: `shcore.hpp` 增加 `GetAwarenessFromDpiAwarenessContext`, `AreDpiAwarenessContextsEqual`, `EnableNonClientDpiScaling`, 文件: `user32.hpp` --- src/Thunks/dxgi.hpp | 36 ++++++++- .../ext-ms-win-rtcore-ntuser-wmpointer.hpp | 50 ++++++++++++ src/Thunks/kernel32.hpp | 28 +++++++ src/Thunks/shcore.hpp | 33 ++++++++ src/Thunks/user32.hpp | 79 ++++++++++++++++++- 5 files changed, 221 insertions(+), 5 deletions(-) diff --git a/src/Thunks/dxgi.hpp b/src/Thunks/dxgi.hpp index f861d5b..46f15c5 100644 --- a/src/Thunks/dxgi.hpp +++ b/src/Thunks/dxgi.hpp @@ -1,4 +1,4 @@ -#if (YY_Thunks_Target < __WindowsNT6_SP2) +#if (YY_Thunks_Target < __WindowsNT6_3) #include #endif @@ -22,7 +22,7 @@ namespace YY::Thunks } if (_ppFactory) - *_ppFactory = nullptr; + *_ppFactory = nullptr; return DXGI_ERROR_UNSUPPORTED; } #endif @@ -52,4 +52,36 @@ namespace YY::Thunks return DXGI_ERROR_UNSUPPORTED; } #endif + +#if (YY_Thunks_Target < __WindowsNT6_3) + // https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_3/nf-dxgi1_3-createdxgifactory2 + // Minimum supported client Windows 8.1 + // Minimum supported server Windows Server 2012 R2 + __DEFINE_THUNK( + dxgi, + 12, + HRESULT, + STDAPICALLTYPE, + CreateDXGIFactory2, + UINT Flags, + REFIID riid, + _COM_Outptr_ void** _ppFactory + ) + { + if (auto const _pfnCreateDXGIFactory2 = try_get_CreateDXGIFactory2()) + { + return _pfnCreateDXGIFactory2(Flags, riid, _ppFactory); + } + + // 根据 VxKex 的实现,会回落到 CreateDXGIFactory1 (Win7) +// #if (YY_Thunks_Target >= __WindowsNT6_SP2) // Windows Vista SP2, Windows 7, Windows 8 + return CreateDXGIFactory1(riid, _ppFactory); +// #endif + + if (_ppFactory) + *_ppFactory = nullptr; + return DXGI_ERROR_UNSUPPORTED; + } +#endif + } diff --git a/src/Thunks/ext-ms-win-rtcore-ntuser-wmpointer.hpp b/src/Thunks/ext-ms-win-rtcore-ntuser-wmpointer.hpp index dc80ed6..e5a7068 100644 --- a/src/Thunks/ext-ms-win-rtcore-ntuser-wmpointer.hpp +++ b/src/Thunks/ext-ms-win-rtcore-ntuser-wmpointer.hpp @@ -122,4 +122,54 @@ return FALSE; } #endif + +#if (YY_Thunks_Target < __WindowsNT6_2) + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-initializetouchinjection + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012 [仅限桌面应用] + __DEFINE_THUNK( + user32, + 8, + BOOL, + WINAPI, + InitializeTouchInjection, + _In_ UINT32 maxCount, + _In_ DWORD dwMode + ) + { + if (const auto _pfnInitializeTouchInjection = try_get_InitializeTouchInjection()) + { + return _pfnInitializeTouchInjection(maxCount, dwMode); + } + + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } +#endif + +#if (YY_Thunks_Target < __WindowsNT6_2) + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-injecttouchinput + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012 [仅限桌面应用] + __DEFINE_THUNK( + user32, + 8, + BOOL, + WINAPI, + InjectTouchInput, + _In_ UINT32 count, + _In_ const POINTER_TOUCH_INFO *contacts + ) + { + if (const auto _pfnInjectTouchInput = try_get_InjectTouchInput()) + { + return _pfnInjectTouchInput(count, contacts); + } + + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } +#endif + + } diff --git a/src/Thunks/kernel32.hpp b/src/Thunks/kernel32.hpp index 93213e2..fe9876b 100644 --- a/src/Thunks/kernel32.hpp +++ b/src/Thunks/kernel32.hpp @@ -502,4 +502,32 @@ namespace YY::Thunks return DEP_SYSTEM_POLICY_TYPE::DEPPolicyAlwaysOff; } #endif // (YY_Thunks_Target < __WindowsNT6_SP1) + + + +#if (YY_Thunks_Target < __WindowsNT6_2) + // https://learn.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getcurrentpackagefullname + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012 [仅限桌面应用] + __DEFINE_THUNK( + kernel32, + 8, + LONG, + WINAPI, + GetCurrentPackageFullName, + _Inout_ UINT32* packageFullNameLength, + _Out_writes_opt_(*packageFullNameLength) PWSTR packageFullName + ) + { + if (const auto _pfnGetCurrentPackageFullName = try_get_GetCurrentPackageFullName()) + { + return _pfnGetCurrentPackageFullName(packageFullNameLength, packageFullName); + } + + return APPMODEL_ERROR_NO_PACKAGE; + } +#endif // (YY_Thunks_Target < __WindowsNT6_SP1) + + + } diff --git a/src/Thunks/shcore.hpp b/src/Thunks/shcore.hpp index 2a8a6ef..fd58f82 100644 --- a/src/Thunks/shcore.hpp +++ b/src/Thunks/shcore.hpp @@ -71,4 +71,37 @@ namespace YY::Thunks return S_OK; } #endif + +#if (YY_Thunks_Target < __WindowsNT6_3) + // https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getprocessdpiawareness + //Windows 8.1 [desktop apps only] + //Windows Server 2012 R2 [desktop apps only] + __DEFINE_THUNK( + shcore, + 8, + HRESULT, + STDAPICALLTYPE, + GetProcessDpiAwareness, + _In_ HANDLE hprocess, + _Out_ PROCESS_DPI_AWARENESS* value + ) + { + if (auto const pGetProcessDpiAwareness = try_get_GetProcessDpiAwareness()) + { + return pGetProcessDpiAwareness(hprocess, value); + } + + // 抄自 VxKex 源码,但其中有个 HANDLE 到 ULONG 的强转,会报警告 + if (hprocess == NULL || hprocess == NtCurrentProcess() + || GetProcessId(hprocess) == (ULONG) NtCurrentTeb()->ClientId.UniqueProcess) + { + *value = IsProcessDPIAware() ? PROCESS_SYSTEM_DPI_AWARE : PROCESS_DPI_UNAWARE; + } else { + *value = PROCESS_DPI_UNAWARE; + } + + return S_OK; + } +#endif + } //namespace YY::Thunks diff --git a/src/Thunks/user32.hpp b/src/Thunks/user32.hpp index 569627e..09197aa 100644 --- a/src/Thunks/user32.hpp +++ b/src/Thunks/user32.hpp @@ -248,6 +248,79 @@ namespace YY::Thunks } #endif +#if (YY_Thunks_Target < __WindowsNT10_14393) + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getawarenessfromdpiawarenesscontext + // Windows 10, version 1607 [desktop apps only] + __DEFINE_THUNK( + user32, + 4, + DPI_AWARENESS, + WINAPI, + GetAwarenessFromDpiAwarenessContext, + _In_ DPI_AWARENESS_CONTEXT value + ) + { + if (auto const pGetAwarenessFromDpiAwarenessContext = try_get_GetAwarenessFromDpiAwarenessContext()) + { + return pGetAwarenessFromDpiAwarenessContext(value); + } + // from VxKex + if(value == DPI_AWARENESS_CONTEXT_UNAWARE || value == DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED){ + return DPI_AWARENESS_UNAWARE; + }else if(value == DPI_AWARENESS_CONTEXT_SYSTEM_AWARE){ + return DPI_AWARENESS_SYSTEM_AWARE; + }else if(value == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE || value == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2){ + return DPI_AWARENESS_PER_MONITOR_AWARE; + }else{ + return DPI_AWARENESS_INVALID; + } + } +#endif + +#if (YY_Thunks_Target < __WindowsNT10_14393) + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-aredpiawarenesscontextsequal + // Windows 10, version 1607 [desktop apps only] + __DEFINE_THUNK( + user32, + 8, + BOOL, + WINAPI, + AreDpiAwarenessContextsEqual, + _In_ DPI_AWARENESS_CONTEXT dpiContextA, + _In_ DPI_AWARENESS_CONTEXT dpiContextB + ) + { + if (auto const pAreDpiAwarenessContextsEqual = try_get_AreDpiAwarenessContextsEqual()) + { + return pAreDpiAwarenessContextsEqual(dpiContextA, dpiContextB); + } + + // from VxKex + return (dpiContextA == dpiContextB); + } +#endif + +#if (YY_Thunks_Target < __WindowsNT10_14393) + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablenonclientdpiscaling + // Windows 10, version 1607 [desktop apps only] + __DEFINE_THUNK( + user32, + 4, + BOOL, + WINAPI, + EnableNonClientDpiScaling, + _In_ HWND hwnd + ) + { + if (auto const pEnableNonClientDpiScaling = try_get_EnableNonClientDpiScaling()) + { + return pEnableNonClientDpiScaling(hwnd); + } + + // from VxKex + return TRUE; + } +#endif #if (YY_Thunks_Target < __WindowsNT10_14393) @@ -805,7 +878,7 @@ namespace YY::Thunks { SetLastError(ERROR_FUNCTION_FAILED); return FALSE; - } + } if (_pParam && internal::GetSystemVersion() < internal::MakeVersion(6, 0)) { @@ -854,7 +927,7 @@ namespace YY::Thunks { SetLastError(ERROR_FUNCTION_FAILED); return FALSE; - } + } #if (YY_Thunks_Target < __WindowsNT6) if (_pParam && internal::GetSystemVersion() < internal::MakeVersion(6, 0)) @@ -875,7 +948,7 @@ namespace YY::Thunks } } } -#endif +#endif return _pfnSystemParametersInfoA(_uAction, _uParam, _pParam, _fWinIni); } #endif