With each new version of Windows, a large number of APIs are added, and it often takes a lot of effort to develop Windows applications that are compatible with older systems. And some open source projects are no longer compatible with some earlier versions of Windows, such as Windows XP, Windows 7...
Isn't there a solution to quickly deal with the problem that the old system can't find the API?
YY-Thunks can solve these kinds of problems quickly and without changing the code. These compatibility issues can be resolved automatically by tweaking the linker. It's easier to make your apps compatible with older versions of Windows!
[ YY-Thunks QQ Group 633710173 ]
Use LoadLibrary and GetProcAddress to dynamically load the API.
If the API doesn't exist, then implement its behavior and get your program running properly.
As follows: GetTickCount64
// Windows XP not support GetTickCount64.
ULONGLONG WINAPI GetTickCount64(VOID)
{
if (auto const _pfnGetTickCount64 = try_get_GetTickCount64())
{
return _pfnGetTickCount64();
}
// Fallback
return GetTickCount();
}
LoadLibrary and GetProcAddress.You can choose one of the following options, but it is recommended to use NuGet first, as NuGet is designed to be foolproof and easier to use.
Project and select Manage NuGet Packages, then search for YY-Thunks and choose the version that suits you, and finally click Install.TargetFramework to net8.0-windows or net9.0-windows。Project and select Manage NuGet Packages, then search for YY-Thunks and choose the version that suits you, and finally click Install.SupportedOSPlatformVersion to 5.1. For example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- ... -->
<TargetFramework>net8.0-windows</TargetFramework>
<SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>
<!-- ... -->
</PropertyGroup>
<!--...-->
</Project>
Directory.Build.props in source directory, and add the following code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<ProjectCapability Include="PackageReferences" />
</ItemGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
<!--Turn on Windows XP support, and you can choose according to your situation.-->
<WindowsTargetPlatformMinVersion>5.1.2600</WindowsTargetPlatformMinVersion>
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<PackageReference Include="YY-Thunks">
<!--YY-Thunks Version-->
<Version>1.1.7-Beta3</Version>
</PackageReference>
</ItemGroup>
<!--从兼容性考虑,继续向上搜索 Directory.Build.props-->
<PropertyGroup>
<DirectoryBuildPropsPath>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</DirectoryBuildPropsPath>
</PropertyGroup>
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(DirectoryBuildPropsPath)' != ''"/>
</Project>
# The Gen parameter must be use `Visual Studio`, as Visual Studio only supports nuget.
# Assuming that the output dir is `.build\x86-Release`, you can modify it as needed.
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=.\build\x86-Release .
# Note the `-- -r` at the end, which is the command to restore the nuget package.
cmake --build .\build\x86-Release --config Release -- -r
cmake --install .\build\x86-Release --config Release
Linker - Input - Additional Dependencies, add objs\$(PlatformShortName)\YY_Thunks_for_WinXP.obj.Linker - System - Minimum Required Version, set to 5.1 (WinXP 32-bit) or 5.2 (WinXP x64 or Win2003).Dynamic Link Library (If you ignore this step, the XP system may crash with thread_local).
Linker - Advanced - Custom Entry Point to DllMainCRTStartupForYY_ThunksLinker- CommandLine add:
/alternatename:_YY_ThunksOriginalDllMainCRTStartup@12=__DllMainCRTStartup@12/alternatename:YY_ThunksOriginalDllMainCRTStartup=_DllMainCRTStartupNote: If your app needs to be compatible with Vista or later, please set
Additional Dependenciestoobjs\$(PlatformShortName)\YY_Thunks_for_Vista.obj。
LLD-Link linkers using obj files will encounter duplicate symbol errors.
-LIBPATH:YY-Thunks_Root_Dir/lib/5.1.2600.0/x86 to the linker and make sure the order is higher than WinSDK.-SUBSYSTEM:WINDOWS",5.1" or -SUBSYSTEM:CONSOLE",5.1" or -SUBSYSTEM:WINDOWS",5.2" or -SUBSYSTEM:CONSOLE",5.2" to linker.Dynamic Link Library (If you ignore this step, the XP system may crash with thread_local)
-ENTRY:DllMainCRTStartupForYY_Thunks to linker-alternatename:_YY_ThunksOriginalDllMainCRTStartup@12=__DllMainCRTStartup@12-alternatename:YY_ThunksOriginalDllMainCRTStartup=_DllMainCRTStartupCompatible with all platforms.
/MD, /MT, /MDd, /MTd).| Thunks Target | At Least Windows SDK Version is required |
|---|---|
| Windows 2000 | SDK 6.0 (VS2008 built-in) |
| Windows XP(2003) | SDK 6.0 (VS2008 built-in) |
| Windows Vista | SDK 6.0 (VS2008 built-in) |
| Windows 7 | SDK 7.0 |
| Windows 8 | SDK 8.0 |
| Windows 8.1 | SDK 8.1 |
| Windows 10 10240 | SDK 10.0.10240 |
| Windows 10 19041 | SDK 10.0.19041 |
At least Windows SDK 6.0 is required.
Note: VC6.0 and VS2005 users should note that the SDK version that comes with these compilers by default is too low. Please upgrade the SDK to version 6.0 or later, and then use YY-Thunks, otherwise the link will not be successful! The different SDK version don't affect your app compatibility with the old system.
See the ThunksList.md
See the releases Changelog
C++
99.7%
With each new version of Windows, a large number of APIs are added, and it often takes a lot of effort to develop Windows applications that are compatible with older systems. And some open source projects are no longer compatible with some earlier versions of Windows, such as Windows XP, Windows 7...
Isn't there a solution to quickly deal with the problem that the old system can't find the API?
YY-Thunks can solve these kinds of problems quickly and without changing the code. These compatibility issues can be resolved automatically by tweaking the linker. It's easier to make your apps compatible with older versions of Windows!
[ YY-Thunks QQ Group 633710173 ]
Use LoadLibrary and GetProcAddress to dynamically load the API.
If the API doesn't exist, then implement its behavior and get your program running properly.
As follows: GetTickCount64
// Windows XP not support GetTickCount64.
ULONGLONG WINAPI GetTickCount64(VOID)
{
if (auto const _pfnGetTickCount64 = try_get_GetTickCount64())
{
return _pfnGetTickCount64();
}
// Fallback
return GetTickCount();
}
LoadLibrary and GetProcAddress.You can choose one of the following options, but it is recommended to use NuGet first, as NuGet is designed to be foolproof and easier to use.
Project and select Manage NuGet Packages, then search for YY-Thunks and choose the version that suits you, and finally click Install.TargetFramework to net8.0-windows or net9.0-windows。Project and select Manage NuGet Packages, then search for YY-Thunks and choose the version that suits you, and finally click Install.SupportedOSPlatformVersion to 5.1. For example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- ... -->
<TargetFramework>net8.0-windows</TargetFramework>
<SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>
<!-- ... -->
</PropertyGroup>
<!--...-->
</Project>
Directory.Build.props in source directory, and add the following code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<ProjectCapability Include="PackageReferences" />
</ItemGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
<!--Turn on Windows XP support, and you can choose according to your situation.-->
<WindowsTargetPlatformMinVersion>5.1.2600</WindowsTargetPlatformMinVersion>
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<PackageReference Include="YY-Thunks">
<!--YY-Thunks Version-->
<Version>1.1.7-Beta3</Version>
</PackageReference>
</ItemGroup>
<!--从兼容性考虑,继续向上搜索 Directory.Build.props-->
<PropertyGroup>
<DirectoryBuildPropsPath>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</DirectoryBuildPropsPath>
</PropertyGroup>
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(DirectoryBuildPropsPath)' != ''"/>
</Project>
# The Gen parameter must be use `Visual Studio`, as Visual Studio only supports nuget.
# Assuming that the output dir is `.build\x86-Release`, you can modify it as needed.
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=.\build\x86-Release .
# Note the `-- -r` at the end, which is the command to restore the nuget package.
cmake --build .\build\x86-Release --config Release -- -r
cmake --install .\build\x86-Release --config Release
Linker - Input - Additional Dependencies, add objs\$(PlatformShortName)\YY_Thunks_for_WinXP.obj.Linker - System - Minimum Required Version, set to 5.1 (WinXP 32-bit) or 5.2 (WinXP x64 or Win2003).Dynamic Link Library (If you ignore this step, the XP system may crash with thread_local).
Linker - Advanced - Custom Entry Point to DllMainCRTStartupForYY_ThunksLinker- CommandLine add:
/alternatename:_YY_ThunksOriginalDllMainCRTStartup@12=__DllMainCRTStartup@12/alternatename:YY_ThunksOriginalDllMainCRTStartup=_DllMainCRTStartupNote: If your app needs to be compatible with Vista or later, please set
Additional Dependenciestoobjs\$(PlatformShortName)\YY_Thunks_for_Vista.obj。
LLD-Link linkers using obj files will encounter duplicate symbol errors.
-LIBPATH:YY-Thunks_Root_Dir/lib/5.1.2600.0/x86 to the linker and make sure the order is higher than WinSDK.-SUBSYSTEM:WINDOWS",5.1" or -SUBSYSTEM:CONSOLE",5.1" or -SUBSYSTEM:WINDOWS",5.2" or -SUBSYSTEM:CONSOLE",5.2" to linker.Dynamic Link Library (If you ignore this step, the XP system may crash with thread_local)
-ENTRY:DllMainCRTStartupForYY_Thunks to linker-alternatename:_YY_ThunksOriginalDllMainCRTStartup@12=__DllMainCRTStartup@12-alternatename:YY_ThunksOriginalDllMainCRTStartup=_DllMainCRTStartupCompatible with all platforms.
/MD, /MT, /MDd, /MTd).| Thunks Target | At Least Windows SDK Version is required |
|---|---|
| Windows 2000 | SDK 6.0 (VS2008 built-in) |
| Windows XP(2003) | SDK 6.0 (VS2008 built-in) |
| Windows Vista | SDK 6.0 (VS2008 built-in) |
| Windows 7 | SDK 7.0 |
| Windows 8 | SDK 8.0 |
| Windows 8.1 | SDK 8.1 |
| Windows 10 10240 | SDK 10.0.10240 |
| Windows 10 19041 | SDK 10.0.19041 |
At least Windows SDK 6.0 is required.
Note: VC6.0 and VS2005 users should note that the SDK version that comes with these compilers by default is too low. Please upgrade the SDK to version 6.0 or later, and then use YY-Thunks, otherwise the link will not be successful! The different SDK version don't affect your app compatibility with the old system.
See the ThunksList.md
See the releases Changelog
C++
99.7%