写程序需要查看Windows的版本号

写程序需要查看Windows的版本号来决定程序如何操作,看到MSDN的GetVersion 函数,这个函数返回一个DWORD的数据,然后自己对数据进行转换得到想要的具体值。 对应值如下: Operating system Version number Windows 7 6.1 Windows Server 2008 R2 6.1 Windows Server 2008 6.0 Windows Vista 6.0 Windows Server 2003 R2 5.2 Windows Server 2003 5.2 Windows XP 5.1 Windows 2000 5.0 转自MSDN的函数参考: GetVersion Function Operating System Version GetVersion Function Retrieves the version number of the current operating system. Note This function has been superseded by GetVersionEx. New applications should use GetVersionEx or VerifyVersionInfo. Syntax C++ DWORD WINAPI GetVersion(void); Parameters This function has no parameters. Return Value If the function succeeds, the return value includes the major and minor version numbers of the operating system in the low-order word, and information about the operating system platform in the high-order word. For all platforms, the low-order word contains the version number of the operating system. The low-order byte of this word specifies the major version number, in hexadecimal notation. The high-order byte specifies the minor version (revision) number, in hexadecimal notation. The high-order bit is zero, the next 7 bits represent the build number, and the low-order byte is 5. Remarks The GetVersionEx function was developed because many existing applications err when examining the packed DWORD value returned by GetVersion, transposing the major and minor version numbers. GetVersionEx forces applications to explicitly examine each element of version information. VerifyVersionInfo eliminates further potential for error by comparing the required system version with the current system version for you. Examples The following code fragment illustrates how to extract information from the GetVersion return value: Copy Code #include #include void main() { DWORD dwVersion = 0; DWORD dwMajorVersion = 0; DWORD dwMinorVersion = 0; DWORD dwBuild = 0; dwVersion = GetVersion(); // Get the Windows version. dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); // Get the build number. if (dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion)); printf("Version is %d.%d (%d)\n", dwMajorVersion, dwMinorVersion, dwBuild); } The GetVersionEx function retrieves the major and minor version numbers and other information about the currently running version of the operating system. The VerifyVersionInfo function enables you to determine whether the current system satisfies a specified set of operating system version conditions. For more information, see the following topics: Getting the System Version Verifying the System Version The following table summarizes the most recent operating system version numbers. Operating system Version number Windows 7 6.1 Windows Server 2008 R2 6.1 Windows Server 2008 6.0 Windows Vista 6.0 Windows Server 2003 R2 5.2 Windows Server 2003 5.2 Windows XP 5.1 Windows 2000 5.0 Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, test for the presence of the feature itself. To determine the best way to test for a feature, refer to the documentation for the feature of interest. The following list discusses some common techniques for feature detection: You can test for the presence of the functions associated with a feature. To test for the presence of a function in a system DLL, call the LoadLibrary function to load the DLL. Then call the GetProcAddress function to determine whether the function of interest is present in the DLL. Use the pointer returned by GetProcAddress to call the function. Note that even if the function is present, it may be a stub that just returns an error code such as ERROR_CALL_NOT_IMPLEMENTED. You can determine the presence of some features by using the GetSystemMetrics function. For example, you can detect multiple display monitors by calling GetSystemMetrics(SM_CMONITORS). There are several versions of the redistributable DLLs that implement shell and common control features. For information about determining which versions are present on the system your application is running on, see the topic Shell and Common Controls Versions. If you must require a particular operating system, be sure to use it as a minimum supported version, rather than design the test for the one operating system. This way, your detection code will continue to work on future versions of Windows. Note that a 32-bit application can detect whether it is running under WOW64 by calling the IsWow64Process function. It can obtain additional processor information by calling the GetNativeSystemInfo function.
posted @ 2011-11-09 22:24  WynstonHou  阅读(251)  评论(0编辑  收藏  举报