Reputation: 37448
I have some code running to detect windows XP which I think should work but what should I replace the '??'s with to detect whether I'm running on Windows XP?
bool IsWindowsXP()
{
bool isWindowsXp = false;
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( GetVersionEx((OSVERSIONINFO*)&osvi) )
{
const DWORD MinXpVersion = ??;
const DWORD MaxXpVersion = ??;
if ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
(vi.dwMajorVersion >= MinXpVersion) &&
(vi.dwMajorVersion <= MinXpVersion))
{
isWindowsXp = false;
}
}
return isWindowsXp;
}
Upvotes: 5
Views: 2235
Reputation: 5559
No need extra library, header, working also on VC++ Express :
BOOL chkxp(){
DWORD version = GetVersion();
DWORD major = (DWORD)(LOBYTE(LOWORD(version)));
DWORD minor = (DWORD)(HIBYTE(LOWORD(version)));
return ((major == 5) && (minor == 1)); // 5.1 is WIN Xp 5.2 is XP x64
}
Upvotes: 2
Reputation: 47954
The SDK has <VersionHelpers.h>
, which provides inline functions for checking for Windows versions. Historically, many developers have gotten these checks wrong, so theses functions were added to make the checks more foolproof.
In particular, IsWindowsXPOrGreater() && !IsWindowsVistaOrGreater()
seems to address your need.
Note that, with the Windows 10 SDK, using GetVersionEx generates deprecation warnings at compile time.
Upvotes: 0
Reputation: 61900
On the documentation page for the OSVERSIONINFOEX
structure, the two relevant fields say this:
For more information, see Remarks.
Down in the remarks section is a handy table:
Operating system Version number dwMajorVersion dwMinorVersion Other Windows 8 6.2 6 2 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION Windows Server 2012 6.2 6 2 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION Windows 7 6.1 6 1 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION Windows Server 2008 R2 6.1 6 1 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION Windows Server 2008 6 6 0 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION Windows Vista 6 6 0 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION Windows Server 2003 R2 5.2 5 2 GetSystemMetrics(SM_SERVERR2) != 0 Windows Home Server 5.2 5 2 OSVERSIONINFOEX.wSuiteMask & VER_SUITE_WH_SERVER Windows Server 2003 5.2 5 2 GetSystemMetrics(SM_SERVERR2) == 0 Windows XP Prof x64 Ed 5.2 5 2 (OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION) && (SYSTEM_INFO.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) Windows XP 5.1 5 1 Not applicable Windows 2000 5 5 0 Not applicable
As seen in the table, XP is 5.1.
Upvotes: 5