I noticed in the source code that you want a more secure way of finding the OS version due to the current one becoming wrong when running Hourglass in compatibility mode.
This is a bit hackish but it should give better results: Get major and minor version numbers of svchost.exe in the System32 folder, at least on XP, XP 64bit, Vista, Win7 and Win8 the major and minor version number is the same as the OS.
The reason to use the svchost.exe file is that no program ever need it (so it is not likely it will ever have a compatibility version) and it's a corner stone of Windows (so it is not likely to be removed in future versions of Windows)
The GetFileVersion-function in the Windows API should do the trick.
EDIT: I was bored, here's an untested function I threw together, it may contain a few errors but it should be close enough to the final implementation to be of help.
Language: C++
enum OSVER
{
FAILED,
XP,
VISTA,
WIN7,
WIN8,
};
// Returns the Windows version if it's a success. The value FAILED it returned if it doesn't succeed.
OSVER GetWindowsVersion()
{
LPTSTR filename[MAX_PATH+1];
UINT value = GetWindowsDirectory(filename, MAX_PATH);
if(value == 0)
{
errorlog("Failed to determinate Windows version, using old method.");
return FAILED;
}
StringCchCat(filename, (size_t)value, _T("\\System32\\svchost.exe"));
LPDWORD handle = NULL;
UINT size = 0;
LPBYTE buffer = NULL;
DWORD infoSize = GetFileVersionInfoSize(filename, handle);
if(infoSize != 0)
{
LPTSTR verInfo = new LPTSTR[infoSize];
BOOL verInfoSuccess = GetFileVersionInfo(filename, handle, infoSize, verInfo);
if(verInfoSuccess != FALSE)
{
BOOL parseSuccess = VerQueryValue(verInfo, "\\",(LPVOID*)&buffer, &size);
if (parseSuccess != FALSE && size > 0)
{
if (((VS_FIXEDFILEINFO *)verInfo)->dwSignature == 0xFEEF04BD)
{
int major = HIWORD(verInfo->dwFileVersionMS);
int minor = LOWORD(verInfo->dwFileVersionMS);
delete [] verInfo; // We no longer need to hold on to this.
/*
svchost.exe versions and their Windows counter parts:
5.2 = XP
6.0 = Vista
6.1 = Win7
6.2 = Win8
*/
if(major == 5 && minor == 2) { return XP; }
if(major == 6)
{
switch(minor)
{
case 0:
{
return VISTA;
break;
}
case 1:
{
return WIN7;
break;
}
case 2:
{
return WIN8;
break;
}
default:
{
break;
}
}
}
errorlog("Unknown Windows version, update the function?");
return FAILED;
}
}
}
delete [] verInfo;
}
errorlog("Failed to determinate Windows version, using old method.");
return FAILED;
}