|
#include "stdafx.h"
#include "OSInfo.h"
//***********************************************
COSInfo::COSInfo()
{
ZeroMemory(&m_osvi, sizeof(OSVERSIONINFO));
m_osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!GetVersionEx(&m_osvi))
ZeroMemory(&m_osvi, sizeof(OSVERSIONINFO));
}
//***********************************************
COSInfo::~COSInfo()
{
}
//***********************************************
EOSType COSInfo::GetOSType(void) const
{
EOSType eOSType = eUnknown;
if(IsWindowsNT())
eOSType = eWinNT;
else if(IsWindows2000())
eOSType = eWin2000;
else if(IsWindowsXP())
eOSType = eWinXP;
else if(IsWindows2003())
eOSType = eWin2003;
else if(IsWindows95())
eOSType = eWin95;
else if(IsWindows98())
eOSType = eWin98;
else if(IsWindowsME())
eOSType = eWinME;
return eOSType;
}
//***********************************************
LPCTSTR COSInfo::GetOSString(void) const
{
struct OSTypeTableEntry
{
EOSType eOSType;
LPCTSTR szOSName;
}
static const OSLookupTable[] =
{
{eUnknown, _T("")}, // Undefined
{eWin95, _T("Windows 95")}, // Windows 95
{eWin98, _T("Windows 98")}, // Windows 98
{eWinME, _T("Windows ME")}, // Windows ME
{eWinNT, _T("Windows NT")}, // Windows NT
{eWin2000, _T("Windows 2000")}, // Windows 2000
{eWinXP, _T("Windows XP")}, // Windows XP
{eWin2003, _T("Windows 2003")} // Windows 2003
};
EOSType eOSType = GetOSType();
_ASSERTE(eOSType < sizeof(OSLookupTable) / sizeof(OSLookupTable[0]));
return OSLookupTable[eOSType].szOSName;
}
//***********************************************
bool COSInfo::IsWindows95(void) const
{
// Windows95 if:
// Major == 4 and Minor == 0 and PlatformId != NT
return (m_osvi.dwMajorVersion == 4 &&
m_osvi.dwMinorVersion == 0 &&
m_osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
bool COSInfo::IsWindows98(void) const
{
// Windows98 if:
// Major >= 4 and Minor > 0 and PlatformId != NT
// (except Major == 4 and Minor == 90 which is ME)
// (note: Major == 4 and Minor == 0 is 95)
return (m_osvi.dwMajorVersion >= 4 &&
m_osvi.dwMinorVersion > 0 &&
m_osvi.dwPlatformId != VER_PLATFORM_WIN32_NT &&
!(m_osvi.dwMajorVersion == 4 && m_osvi.dwMinorVersion == 90)) ? true : false;
}
//***********************************************
bool COSInfo::IsWindowsME(void) const
{
// WindowsME if:
// Major == 4 and Minor == 90 and PlatformId != NT
return (m_osvi.dwMajorVersion == 4 &&
m_osvi.dwMinorVersion == 90 &&
m_osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
bool COSInfo::IsWindowsNT(void) const
{
// WindowsNT4 if:
// Major == 4 and Minor == 0 and PlatformId == NT
return (m_osvi.dwMajorVersion == 4 &&
m_osvi.dwMinorVersion == 0 &&
m_osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
bool COSInfo::IsWindows2000(void) const
{
// Windows2000 if:
// Major == 5 and Minor == 0 and PlatformId == NT
return (m_osvi.dwMajorVersion == 5 &&
m_osvi.dwMinorVersion == 0 &&
m_osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
bool COSInfo::IsWindowsXP(void) const
{
// WindowsXP if:
// Major == 5 and Minor == 1 and PlatformId == NT
return (m_osvi.dwMajorVersion == 5 &&
m_osvi.dwMinorVersion == 1 &&
m_osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
bool COSInfo::IsWindows2003(void) const
{
// Windows2003 if:
// Major == 5 and Minor == 2 and PlatformId == NT
return (m_osvi.dwMajorVersion == 5 &&
m_osvi.dwMinorVersion == 2 &&
m_osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
bool COSInfo::IsNT(void) const
{
return (m_osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) ? true : false;
}
//***********************************************
DWORD COSInfo::GetMajor(void) const
{
return m_osvi.dwMajorVersion;
}
//***********************************************
DWORD COSInfo::GetMinor(void) const
{
return m_osvi.dwMinorVersion;
}
//***********************************************
DWORD COSInfo::GetBuild(void) const
{
return m_osvi.dwBuildNumber;
}
//***********************************************
DWORD COSInfo::GetPlatformId(void) const
{
return m_osvi.dwPlatformId;
}
//***********************************************
LPCTSTR COSInfo::GetCSDString(void) const
{
return m_osvi.szCSDVersion;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.