Skip to content

Commit

Permalink
Fea #29, 添加PowerDeterminePlatformRole,PowerDeterminePlatformRoleEx
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Mar 13, 2023
1 parent 3249536 commit cc1e3ca
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@
| ---- | -----------
| PdhAddEnglishCounterW(A) | 不存在时,调用PdhAddCounterW(A)。

## powrprof.dll
| 函数 | Fallback
| ---- | -----------
| PowerDeterminePlatformRole | 不存在时,返回PlatformRoleDesktop。
| PowerDeterminePlatformRoleEx | 不存在时,调用PlatformRoleDesktop。

## psapi.dll
| 函数 | Fallback
| ---- | -----------
Expand Down
1 change: 1 addition & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
_APPLY(mfplat, "mfplat" , 0 ) \
_APPLY(bluetoothapis, "bluetoothapis" , 0 ) \
_APPLY(netapi32, "netapi32" , 0 ) \
_APPLY(powrprof, "powrprof" , 0 ) \
_APPLY(api_ms_win_core_winrt_l1_1_0, "api-ms-win-core-winrt-l1-1-0" , 0 ) \
_APPLY(api_ms_win_core_winrt_string_l1_1_0, "api-ms-win-core-winrt-string-l1-1-0", 0 ) \
_APPLY(api_ms_win_core_winrt_error_l1_1_0, "api-ms-win-core-winrt-error-l1-1-0" , 0 ) \
Expand Down
42 changes: 42 additions & 0 deletions src/Thunks/api-ms-win-power-base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#if (YY_Thunks_Support_Version < NTDDI_WIN8)
#include <powrprof.h>
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN8)
#pragma comment(lib, "PowrProf.lib")
#endif

namespace YY
{
namespace Thunks
{
#if (YY_Thunks_Support_Version < NTDDI_WIN8)

// 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用]
// 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用]
__DEFINE_THUNK(
powrprof,
4,
POWER_PLATFORM_ROLE,
WINAPI,
PowerDeterminePlatformRoleEx,
_In_ ULONG _uVersion
)
{
if (auto const _pfnPowerDeterminePlatformRoleEx = try_get_PowerDeterminePlatformRoleEx())
{
return _pfnPowerDeterminePlatformRoleEx(_uVersion);
}

if (_uVersion == POWER_PLATFORM_ROLE_V1)
{
return PowerDeterminePlatformRole();
}
else
{
return PlatformRoleUnspecified;
}
}
#endif
}
}
31 changes: 31 additions & 0 deletions src/Thunks/powrprof.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if (YY_Thunks_Support_Version < NTDDI_VISTA)
#include <powrprof.h>
#endif

namespace YY
{
namespace Thunks
{
#if (YY_Thunks_Support_Version < NTDDI_VISTA)

// 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用]
// 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用]
__DEFINE_THUNK(
powrprof,
0,
POWER_PLATFORM_ROLE,
WINAPI,
PowerDeterminePlatformRole,
)
{
if (auto const _pfnPowerDeterminePlatformRole = try_get_PowerDeterminePlatformRole())
{
return _pfnPowerDeterminePlatformRole();
}

// 假定自己没有电池
return PlatformRoleDesktop;
}
#endif
}
}
2 changes: 2 additions & 0 deletions src/YY-Thunks.UnitTest/YY-Thunks.UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@
<ItemGroup>
<ClInclude Include="..\Thunks\api-ms-win-core-com.hpp" />
<ClInclude Include="..\Thunks\api-ms-win-eventing-provider.hpp" />
<ClInclude Include="..\Thunks\api-ms-win-power-base.hpp" />
<ClInclude Include="..\Thunks\bcrypt.hpp" />
<ClInclude Include="..\Thunks\bluetoothapis.hpp" />
<ClInclude Include="..\Thunks\ext-ms-win-ntuser-window.hpp" />
<ClInclude Include="..\Thunks\Iphlpapi.hpp" />
<ClInclude Include="..\Thunks\mfplat.hpp" />
<ClInclude Include="..\Thunks\netapi32.hpp" />
<ClInclude Include="..\Thunks\Pdh.hpp" />
<ClInclude Include="..\Thunks\powrprof.hpp" />
<ClInclude Include="..\Thunks\userenv.hpp" />
<ClInclude Include="pch.h" />
<ClInclude Include="..\Thunks\api-ms-win-core-datetime.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions src/YY-Thunks.UnitTest/YY-Thunks.UnitTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@
<ClInclude Include="..\Thunks\netapi32.hpp">
<Filter>Thunks</Filter>
</ClInclude>
<ClInclude Include="..\Thunks\api-ms-win-power-base.hpp">
<Filter>Thunks</Filter>
</ClInclude>
<ClInclude Include="..\Thunks\powrprof.hpp">
<Filter>Thunks</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\def\x86\PSAPI2Kernel32.def">
Expand Down

0 comments on commit cc1e3ca

Please sign in to comment.