From: http://flyxxtt.blogbus.com/logs/42705986.html
Windows APIThere are two functions availableObtain the system version information.:GetversionAndGetversionex.
GetversionThis function has plagued a lot of programmers, its original design is in the DWORD return value with the low word that represents the version of the MS-DOS, the high word that representsWindows Version. For each word, the high byte represents the major version number, and the low byte represents the minor version number. However, the programmer who compiled this function makes a mistake, so that the function returnsWindows Version(That is, the major version number is put to the low byte, and the minor version number is put to the high byte ). When this error is found, many programmers are using this function. Microsoft has to correct the error and directly change the original API document.
To solveGetversionMicrosoft developed a new function.Getversionex, Use itObtain more detailed Windows version information.Next I will writeGetversionex.
Function prototype:
BoolGetversionex(Posversioninfo pversioninformation );
Let's take a look at the osversioninfoex structure:
Typedef struct {
DWORD dwosversioninfosize; // In useGetversionexPreviously, we want to initialize this as the size of the structure.
DWORD dwmajorversion; // Main system version
DWORD dwminorversion; // System minor version number
DWORD dwbuildnumber; // System build number
DWORD dwplatformid; // Platform supported by the system (see Appendix 1)
Tchar szcsdversion [128]; // System patch package name
Word wservicepackmajor; // Main version of the system patch package
Word wservicepackminor; // Version of the system patch
Word wsuitemask; // Identify the Program Group on the system (see Appendix 2)
Byte wproducttype; // Identify the system type (see appendix 3)
Byte wreserved;
// Reserved, not used
} Osversioninfoex, * posversioninfoex;
This structure appears after Windows 2000. The osversioninfo structure of earlier versions does not have members such as wservicepackmajor, wservicepackminor, wsuitemask, wproducttype, and wreserved.
Then, initialize the structure size before calling the function:
Osversioninfoex OS;
OS. dwosversioninfosize = sizeof (OS );
If the return value is true, the operation is successful:
If (! Getversionex (osversioninfo *) & OS ))
{
Return false;
}
After the function is called successfully, you can view it through osversioninfoex.System Version Information.
The following is a system version used to determineOperating system nameExample:
Cstring getsystemname ()
{
System_info Info;
// Use the system_info structure to determine the 64-bit AMD processor
Getsysteminfo (& info );
// Call the getsysteminfo function to fill in the Structure
Osversioninfoex OS;
OS. dwosversioninfosize = sizeof (osversioninfoex );
If (getversionex (osversioninfo *) & OS ))
{
Cstring vname;
// Perform the following operations based on version informationSystem name
Switch (OS. dwmajorversion ){
// Determine the major version number
Case 4:
Switch (OS. dwminorversion ){
// Judge the minor version number
Case 0:
If (OS. dwplatformid = ver_platform_win32_nt)