<Reprinted please indicate the source, please respect others' labor achievements>
// Headerfile
/** @ Brief OS version definition */
Enum winverdef
{
Win_ver_unknown =-1,
Win_ver_95 = 0,
Win_ver_98,
Win_ver_me,
Win_ver_nt4,
Win_ver_2k,
Win_ver_xp,
Win_ver_xp64,
Win_ver_2k3,
Win_ver_2k3r2,
Win_ver_vista,
Win_ver_2k8,
Win_ver_2k8r2,
Win_ver_win7,
};
/**
@ Brief: checks whether the current operating system is updated later than the specified operating system
@ See winverdef
@ Param [in] the operating system version specified by specver
@ Param [out] iresult returned result/n
If the returned result is greater than 0, the current operating system is newer than the specified operating system./n
If the returned result is 0, the current operating system is the same as the specified operating system./n
If the returned result is smaller than 0, the current operating system is earlier than the specified operating system.
@ Retval true: the function is successfully executed. Compare and judge the version based on the iresult parameter.
@ Retval false: The function failed to be executed.
@ Note none
@ Exception none
*/
Bool isoldersystem (winverdef specver, int * iresult );
/**
@ Brief returns the current operating system version
@ See winverdef
@ Param [out] enumeration value of winver's current operating system version
@ Return true: the function is successfully executed. The winver parameter returns the operating system version.
@ Return false: The function failed to be executed.
@ Note none
@ Exception none
*/
Bool getwindowsversion (winverdef * winver );
// CPP
// Define the current master version number of the Operating System
Enum winvermajor
{
Win_major_nt4_me_98_95 = 4,
Win_major_2k3r2_2k3_xp_2k = 5,
Win_major_win7_2k8r2_2k8_vista = 6,
};
// Define the current version number of the Operating System
Enum winverminor
{
Win_minor_2k8_vista_2k_nt4_95 = 0,
Win_minor_win7_2k8r2_xp = 1,
Win_minor_2k3r2_2k3_xp64 = 2,
Win_minor_98 = 10,
Win_minor_me = 90,
};
Typedef void (winapi * getnativesysteminfofunc) (lpsystem_info );
/** @ Brief returns the current operating system version */
Bool getwindowsversion (winverdef * winver)
{
Osversioninfoex osversioninfo;
Zeromemory (& osversioninfo, sizeof (osversioninfo ));
Osversioninfo. dwosversioninfosize = sizeof (osversioninfo );
* Winver = win_ver_unknown;
If (null = winver | false = getversionex (lposversioninfo) & osversioninfo ))
{
Return false;
}
Switch (osversioninfo. dwmajorversion)
{
Case win_major_nt4_me_98_95:
Switch (osversioninfo. dwminorversion)
{
Case win_minor_2k8_vista_2k_nt4_95:
If (ver_platform_win32_nt = osversioninfo. dwplatformid)
{
* Winver = win_ver_nt4;
}
Else
{
* Winver = win_ver_95;
}
Break;
Case win_minor_98:
* Winver = win_ver_98;
Break;
Case win_minor_me:
* Winver = win_ver_me;
Break;
Default:
Break;
}
Break;
Case win_major_2k3r2_2k3_xp_2k:
Switch (osversioninfo. dwminorversion)
{
Case win_minor_2k8_vista_2k_nt4_95:
* Winver = win_ver_2k;
Break;
Case win_minor_win7_2k8r2_xp:
* Winver = win_ver_xp;
Break;
Case win_minor_2k3r2_2k3_xp64:
If (ver_nt_workstation = osversioninfo. wproducttype)
{
* Winver = win_ver_xp64;
Break;
}
If (0! = Getsystemmetrics (sm_serverr2 ))
{
* Winver = win_ver_2k3r2;
}
Else
{
* Winver = win_ver_2k3;
}
Break;
Default:
Break;
}
Break;
Case win_major_win7_2k8r2_2k8_vista:
Switch (osversioninfo. dwminorversion)
{
Case win_minor_2k8_vista_2k_nt4_95:
If (ver_nt_workstation = osversioninfo. wproducttype)
{
* Winver = win_ver_vista;
}
Else
{
* Winver = win_ver_2k8;
}
Break;
Case win_minor_win7_2k8r2_xp:
If (ver_nt_workstation = osversioninfo. wproducttype)
{
* Winver = win_ver_win7;
}
Else
{
* Winver = win_ver_2k8r2;
}
Break;
Default:
Break;
}
Break;
Default:
Break;
}
Return true;
}
/** @ Brief: determines whether the current operating system is more updated than the system specified by sepcver */
Bool isoldersystem (winverdef specver, int * iresult)
{
If (null = iresult)
{
Return false;
}
Winverdef currver = win_ver_unknown;
If (false = getwindowsversion (& currver) | win_ver_unknown = currver)
{
Return false;
}
Else
{
* Iresult = currver-specver;
}
Return true;
}