Reputation: 2604
I would like to know if there is any chance to check which Windows version I really use. Something similar to: How do I check OS with a preprocessor directive?.
I tried code from MSDN:
But any of them gave me good results (for example: according to http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx my code should print 5.1 when Im on Windows XP but it showed 5 ...)
Is there any reliable way (I would prefer preprocessor directives way) to find out which Windows I'm using?
My code:
#include <windows.h>
#include <iostream>
int main()
{
OSVERSIONINFO osvi;
BOOL bIsWindowsXPorLater;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
// I HAD THIS, AND IT WAS WRONG! :<
std::cout << osvi.dwMajorVersion << "\n";
// CHANGED THE ABOVE LINE TO THE LINE BELOW AND IT IS OK NOW :D
std::cout << osvi.dwMajorVersion << "." << osvi.dwMinorVersion << "\n";
return 0;
}
Upvotes: 0
Views: 1236
Reputation: 4888
You are actually getting the right result. But you are only printing the major version:
std::cout << osvi.dwMajorVersion << "\n";
Instead try using:
if (osvi.dwMinorVersion >= 1) {
std::cout << osvi.dwMajorVersion << "." << osvi.dwMinorVersion << std::endl;
} else {
std::cout << osvi.dwMajorVersion << std::endl;
}
Upvotes: 2