From 563b0b4d05aeebe1389fe7fabb6fb3752202326a 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] =?UTF-8?q?Fea=20#71,=20=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=BA=9BQT=E7=BC=BA=E5=A4=B1=E7=9A=84=E6=8E=A5=E5=8F=A3=20=20?= =?UTF-8?q?=20-=20=E6=B7=BB=E5=8A=A0=20CreateDXGIFactory2=20=20=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20InitializeTouchInjection=20=20=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20InjectTouchInput=20=20=20-=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20GetCurrentPackageFullName=20=20=20-=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20GetProcessDpiAwareness=20=20=20-=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20GetAwarenessFromDpiAwarenessContext=20=20=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20AreDpiAwarenessContextsEqual=20=20=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20EnableNonClientDpiScaling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThunksList.md | 12 ++- src/Thunks/dxgi.hpp | 68 ++++++++++---- .../ext-ms-win-rtcore-ntuser-wmpointer.hpp | 50 ++++++++++ src/Thunks/kernel32.hpp | 28 +++++- src/Thunks/shcore.hpp | 50 ++++++++-- src/Thunks/user32.hpp | 91 ++++++++++++++++++- 6 files changed, 268 insertions(+), 31 deletions(-) diff --git a/ThunksList.md b/ThunksList.md index f5031bb..bce4fb1 100644 --- a/ThunksList.md +++ b/ThunksList.md @@ -227,8 +227,9 @@ ## dxgi.dll | 函数 | Fallback | ---- | ----------- -| CreateDXGIFactory1 | 不存在时,返回 `DXGI_ERROR_UNSUPPORTED`。 -| CreateDXGIFactory | 不存在时,返回 `DXGI_ERROR_UNSUPPORTED`。 +| CreateDXGIFactory | 返回 `DXGI_ERROR_UNSUPPORTED`。 +| CreateDXGIFactory1 | 调用 CreateDXGIFactory。 +| CreateDXGIFactory2 | 调用 CreateDXGIFactory1。 ## dxva2.dll | 函数 | Fallback @@ -540,6 +541,7 @@ | WerUnregisterRuntimeExceptionModule | 不存在时,返回S_OK。 | Wow64GetThreadContext | 不存在时,调用GetThreadContext或者返回ERROR_INVALID_PARAMETER。 | SetDefaultDllDirectories | 不存在时,手工控制LoadLibrary加载顺序。 +| GetCurrentPackageFullName | 返回 APPMODEL_ERROR_NO_PACKAGE。 ## mfplat.dll | 函数 | Fallback @@ -647,6 +649,7 @@ | 函数 | Fallback | ---- | ----------- | GetDpiForMonitor | 不存在时,调用GetDeviceCaps。 +| GetProcessDpiAwareness | 调用 IsProcessDPIAware。 | SetProcessDpiAwareness | 不存在时,调用SetProcessDPIAware。 | SetProcessDPIAware | 不存在时,直接返回 TRUE。 @@ -725,6 +728,11 @@ | GetPointerDevice | 不存在时,假装没有触摸设备。 | GetPointerPenInfo | 不存在时,假装没有触摸设备。 | GetPointerType | 不存在时,假装没有触摸设备。 +| InitializeTouchInjection | 报告错误 ERROR_INVALID_PARAMETER。 +| InjectTouchInput | 报告错误 ERROR_INVALID_PARAMETER。 +| GetAwarenessFromDpiAwarenessContext | 内部实现。 +| AreDpiAwarenessContextsEqual | 内部实现。 +| EnableNonClientDpiScaling | 假装成功。 ## userenv.dll | 函数 | Fallback diff --git a/src/Thunks/dxgi.hpp b/src/Thunks/dxgi.hpp index f861d5b..32cfcec 100644 --- a/src/Thunks/dxgi.hpp +++ b/src/Thunks/dxgi.hpp @@ -1,55 +1,85 @@ -#if (YY_Thunks_Target < __WindowsNT6_SP2) -#include +#if (YY_Thunks_Target < __WindowsNT6_3) +#include +#endif + +#if (YY_Thunks_Target < __WindowsNT6_3) && !defined(__Comment_Lib_dxgi) +#define __Comment_Lib_dxgi +#pragma comment(lib, "DXGI.lib") #endif namespace YY::Thunks { +#if (YY_Thunks_Target < __WindowsNT6) + + // Minimum supported client Windows Vista + // Minimum supported server Windows Server 2008 + __DEFINE_THUNK( + dxgi, + 8, + HRESULT, + STDAPICALLTYPE, + CreateDXGIFactory, + REFIID _IID, + _COM_Outptr_ void** _ppFactory + ) + { + if (auto const _pfnCreateDXGIFactory = try_get_CreateDXGIFactory()) + { + return _pfnCreateDXGIFactory(_IID, _ppFactory); + } + + if (_ppFactory) + *_ppFactory = nullptr; + return DXGI_ERROR_UNSUPPORTED; + } +#endif + + #if (YY_Thunks_Target < __WindowsNT6_SP2) + // 最低受支持的客户端 Windows 7 [桌面应用 |UWP 应用] + // 最低受支持的服务器 Windows Server 2008 R2[桌面应用 | UWP 应用] __DEFINE_THUNK( dxgi, 8, HRESULT, WINAPI, CreateDXGIFactory1, - REFIID riid, + REFIID _IID, _COM_Outptr_ void ** _ppFactory ) { if (const auto _pfnCreateDXGIFactory1 = try_get_CreateDXGIFactory1()) { - return _pfnCreateDXGIFactory1(riid, _ppFactory); + return _pfnCreateDXGIFactory1(_IID, _ppFactory); } - if (_ppFactory) - *_ppFactory = nullptr; - return DXGI_ERROR_UNSUPPORTED; + return CreateDXGIFactory(_IID, _ppFactory); } #endif -#if (YY_Thunks_Target < __WindowsNT6) +#if (YY_Thunks_Target < __WindowsNT6_3) - // Minimum supported client Windows Vista - // Minimum supported server Windows Server 2008 + // Minimum supported client Windows 8.1 + // Minimum supported server Windows Server 2012 R2 __DEFINE_THUNK( dxgi, - 8, + 12, HRESULT, STDAPICALLTYPE, - CreateDXGIFactory, - REFIID riid, + CreateDXGIFactory2, + UINT _fFlags, + REFIID _IID, _COM_Outptr_ void** _ppFactory ) { - if (auto const _pfnCreateDXGIFactory = try_get_CreateDXGIFactory()) + if (auto const _pfnCreateDXGIFactory2 = try_get_CreateDXGIFactory2()) { - return _pfnCreateDXGIFactory(riid, _ppFactory); + return _pfnCreateDXGIFactory2(_fFlags, _IID, _ppFactory); } - - if (_ppFactory) - *_ppFactory = nullptr; - return DXGI_ERROR_UNSUPPORTED; + + return CreateDXGIFactory1(_IID, _ppFactory); } #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..33d8775 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) + + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012 [仅限桌面应用] + __DEFINE_THUNK( + user32, + 8, + BOOL, + WINAPI, + InitializeTouchInjection, + _In_ UINT32 _uMaxCount, + _In_ DWORD _udwMode + ) + { + if (const auto _pfnInitializeTouchInjection = try_get_InitializeTouchInjection()) + { + return _pfnInitializeTouchInjection(_uMaxCount, _udwMode); + } + + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } +#endif + + +#if (YY_Thunks_Target < __WindowsNT6_2) + + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012 [仅限桌面应用] + __DEFINE_THUNK( + user32, + 8, + BOOL, + WINAPI, + InjectTouchInput, + _In_ UINT32 _cCount, + _In_ const POINTER_TOUCH_INFO* _pContacts + ) + { + if (const auto _pfnInjectTouchInput = try_get_InjectTouchInput()) + { + return _pfnInjectTouchInput(_cCount, _pContacts); + } + + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } +#endif } diff --git a/src/Thunks/kernel32.hpp b/src/Thunks/kernel32.hpp index 93213e2..2a1742d 100644 --- a/src/Thunks/kernel32.hpp +++ b/src/Thunks/kernel32.hpp @@ -1,4 +1,6 @@ - +#if (YY_Thunks_Target < __WindowsNT6_2) +#include +#endif namespace YY::Thunks { @@ -502,4 +504,28 @@ namespace YY::Thunks return DEP_SYSTEM_POLICY_TYPE::DEPPolicyAlwaysOff; } #endif // (YY_Thunks_Target < __WindowsNT6_SP1) + + +#if (YY_Thunks_Target < __WindowsNT6_2) + + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012 [仅限桌面应用] + __DEFINE_THUNK( + kernel32, + 8, + LONG, + WINAPI, + GetCurrentPackageFullName, + _Inout_ UINT32* _pcPackageFullNameLength, + _Out_writes_opt_(*_pcPackageFullNameLength) PWSTR _szPackageFullName + ) + { + if (const auto _pfnGetCurrentPackageFullName = try_get_GetCurrentPackageFullName()) + { + return _pfnGetCurrentPackageFullName(_pcPackageFullNameLength, _szPackageFullName); + } + + return APPMODEL_ERROR_NO_PACKAGE; + } +#endif // (YY_Thunks_Target < __WindowsNT6_2) } diff --git a/src/Thunks/shcore.hpp b/src/Thunks/shcore.hpp index 2a8a6ef..2419047 100644 --- a/src/Thunks/shcore.hpp +++ b/src/Thunks/shcore.hpp @@ -47,28 +47,66 @@ namespace YY::Thunks #if (YY_Thunks_Target < __WindowsNT6_3) - //Windows 8.1 [desktop apps only] - //Windows Server 2012 R2 [desktop apps only] + // Windows 8.1 [desktop apps only] + // Windows Server 2012 R2 [desktop apps only] __DEFINE_THUNK( shcore, 4, HRESULT, STDAPICALLTYPE, SetProcessDpiAwareness, - _In_ PROCESS_DPI_AWARENESS value + _In_ PROCESS_DPI_AWARENESS _eValue ) { - if (auto const pSetProcessDpiAwareness = try_get_SetProcessDpiAwareness()) + if (auto const _pfnSetProcessDpiAwareness = try_get_SetProcessDpiAwareness()) { - return pSetProcessDpiAwareness(value); + return _pfnSetProcessDpiAwareness(_eValue); } - if (value != PROCESS_DPI_UNAWARE) + switch (_eValue) { + case PROCESS_DPI_UNAWARE: + return S_OK; + case PROCESS_SYSTEM_DPI_AWARE: + case PROCESS_PER_MONITOR_DPI_AWARE: return SetProcessDPIAware() ? S_OK : E_FAIL; + default: + return E_INVALIDARG; } + } +#endif + +#if (YY_Thunks_Target < __WindowsNT6_3) + + // 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* _peValue + ) + { + if (auto const _pfnGetProcessDpiAwareness = try_get_GetProcessDpiAwareness()) + { + return _pfnGetProcessDpiAwareness(_hProcess, _peValue); + } + + if (_hProcess == NULL || _hProcess == NtCurrentProcess() + || GetProcessId(_hProcess) == (ULONG)NtCurrentTeb()->ClientId.UniqueProcess) + { + *_peValue = IsProcessDPIAware() ? PROCESS_SYSTEM_DPI_AWARE : PROCESS_DPI_UNAWARE; + } + else + { + *_peValue = PROCESS_DPI_UNAWARE; + } return S_OK; } #endif + } //namespace YY::Thunks diff --git a/src/Thunks/user32.hpp b/src/Thunks/user32.hpp index 569627e..eaef9f3 100644 --- a/src/Thunks/user32.hpp +++ b/src/Thunks/user32.hpp @@ -805,7 +805,7 @@ namespace YY::Thunks { SetLastError(ERROR_FUNCTION_FAILED); return FALSE; - } + } if (_pParam && internal::GetSystemVersion() < internal::MakeVersion(6, 0)) { @@ -854,7 +854,7 @@ namespace YY::Thunks { SetLastError(ERROR_FUNCTION_FAILED); return FALSE; - } + } #if (YY_Thunks_Target < __WindowsNT6) if (_pParam && internal::GetSystemVersion() < internal::MakeVersion(6, 0)) @@ -875,8 +875,93 @@ namespace YY::Thunks } } } -#endif +#endif return _pfnSystemParametersInfoA(_uAction, _uParam, _pParam, _fWinIni); } #endif + + +#if (YY_Thunks_Target < __WindowsNT10_14393) + + // 最低受支持的客户端 Windows 10版本 1607 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2016[仅限桌面应用] + __DEFINE_THUNK( + user32, + 4, + DPI_AWARENESS, + WINAPI, + GetAwarenessFromDpiAwarenessContext, + _In_ DPI_AWARENESS_CONTEXT _hValue + ) + { + if (auto const _pfnGetAwarenessFromDpiAwarenessContext = try_get_GetAwarenessFromDpiAwarenessContext()) + { + return _pfnGetAwarenessFromDpiAwarenessContext(_hValue); + } + + if (_hValue == DPI_AWARENESS_CONTEXT_UNAWARE || _hValue == DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) + { + return DPI_AWARENESS_UNAWARE; + } + else if (_hValue == DPI_AWARENESS_CONTEXT_SYSTEM_AWARE) + { + return DPI_AWARENESS_SYSTEM_AWARE; + } + else if (_hValue == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE || _hValue == 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) + + // 最低受支持的客户端 Windows 10版本 1607 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2016[仅限桌面应用] + __DEFINE_THUNK( + user32, + 8, + BOOL, + WINAPI, + AreDpiAwarenessContextsEqual, + _In_ DPI_AWARENESS_CONTEXT _hDpiContextA, + _In_ DPI_AWARENESS_CONTEXT _hDpiContextB + ) + { + if (auto const _pfnAreDpiAwarenessContextsEqual = try_get_AreDpiAwarenessContextsEqual()) + { + return _pfnAreDpiAwarenessContextsEqual(_hDpiContextA, _hDpiContextB); + } + + return _hDpiContextA == _hDpiContextB; + } +#endif + + +#if (YY_Thunks_Target < __WindowsNT10_14393) + + // 最低受支持的客户端 Windows 10版本 1607 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2016[仅限桌面应用] + __DEFINE_THUNK( + user32, + 4, + BOOL, + WINAPI, + EnableNonClientDpiScaling, + _In_ HWND _hWnd + ) + { + if (auto const _pfnEnableNonClientDpiScaling = try_get_EnableNonClientDpiScaling()) + { + return _pfnEnableNonClientDpiScaling(_hWnd); + } + + return TRUE; + } +#endif } //namespace YY::Thunks