- 1 year ago
Windows SAPI error : 'GetVersionExA': was declared deprecated
The GetVersionEx
function in the Windows System API (SAPI) has been deprecated since Windows 8.1 and is no longer recommended for use. The deprecation is indicated by the warning message you encountered regarding the use of GetVersionExA
being deprecated.
Instead of GetVersionEx
, it is recommended to use the VerifyVersionInfo
or VerifyVersionInfoEx
functions, which provide a more accurate and reliable way to determine the operating system version.
Here's an example of how you can use VerifyVersionInfo
to check the operating system version:
cpp#include <Windows.h>
#include <iostream>
bool IsWindowsVersionAtLeast(DWORD majorVersion, DWORD minorVersion)
{
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
osvi.dwMajorVersion = majorVersion;
osvi.dwMinorVersion = minorVersion;
DWORDLONG conditionMask = 0;
VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
if (VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, conditionMask))
{
return true;
}
return false;
}
int main()
{
if (IsWindowsVersionAtLeast(10, 0))
{
std::cout << "Running on Windows 10 or later\n";
}
else if (IsWindowsVersionAtLeast(6, 2))
{
std::cout << "Running on Windows 8.1 or later\n";
}
else
{
std::cout << "Running on an older version of Windows\n";
}
return 0;
}
In this example, the IsWindowsVersionAtLeast
function checks if the current operating system version is at least the specified major and minor version. The function uses VerifyVersionInfo
to perform the version check.
Please note that the specific major and minor versions you need to check may vary depending on your requirements. Modify the IsWindowsVersionAtLeast
function according to your desired version check.
By using the recommended VerifyVersionInfo
function instead of the deprecated GetVersionEx
, you can determine the operating system version without encountering the deprecation warning.