Skip to content

Commit

Permalink
tried to add some functions (#113)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
BH2WFR authored Aug 28, 2024
1 parent ac63103 commit dfae40e
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 5 deletions.
36 changes: 34 additions & 2 deletions src/Thunks/dxgi.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (YY_Thunks_Target < __WindowsNT6_SP2)
#if (YY_Thunks_Target < __WindowsNT6_3)
#include <dxgi.h>
#endif

Expand All @@ -22,7 +22,7 @@ namespace YY::Thunks
}

if (_ppFactory)
*_ppFactory = nullptr;
*_ppFactory = nullptr;
return DXGI_ERROR_UNSUPPORTED;
}
#endif
Expand Down Expand Up @@ -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

}
50 changes: 50 additions & 0 deletions src/Thunks/ext-ms-win-rtcore-ntuser-wmpointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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


}
28 changes: 28 additions & 0 deletions src/Thunks/kernel32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)



}
33 changes: 33 additions & 0 deletions src/Thunks/shcore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
79 changes: 76 additions & 3 deletions src/Thunks/user32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -805,7 +878,7 @@ namespace YY::Thunks
{
SetLastError(ERROR_FUNCTION_FAILED);
return FALSE;
}
}

if (_pParam && internal::GetSystemVersion() < internal::MakeVersion(6, 0))
{
Expand Down Expand Up @@ -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))
Expand All @@ -875,7 +948,7 @@ namespace YY::Thunks
}
}
}
#endif
#endif
return _pfnSystemParametersInfoA(_uAction, _uParam, _pParam, _fWinIni);
}
#endif
Expand Down

0 comments on commit dfae40e

Please sign in to comment.