Windows API one-day training (73) getversionex Function
Windows development is still very fast, from Win95 to Win98, to Win2000 and XP systems. Each system has different functions. to distinguish different systems in a program, you need to obtain the system version information. For example, there is a firewall in XP, but not in other previous systems. However, sometimes a server program or BT program is compiled, and a port must be set to receive external connections. Therefore, you need to set the firewall port in the XP system, in XP systems, there is no need to set ports. The getversionex function can be used to differentiate different systems.
The getversionex function declaration is as follows:
Winbaseapi
Bool
Winapi
Getversionexa (
_ Inout lposversioninfoa lpversioninformation
);
Winbaseapi
Bool
Winapi
Getversionexw (
_ Inout lposversioninfow lpversioninformation
);
# Ifdef Unicode
# Define getversionex getversionexw
# Else
# Define getversionex getversionexa
# Endif //! Unicode
Lpversioninformation is the information of the system version.
An example of calling a function is as follows:
#001 //
#002 // obtain the name of the current logon user.
#003 // Cai junsheng 2007/11/14 QQ: 9073204 Shenzhen
#004 void getwinversion (void)
#005 {
#006 //
#007 osversioninfo osvi;
#008 osvi. dwosversioninfosize = sizeof (osversioninfo );
#009
#010 // obtain the system version information.
#011: getversionex (& osvi );
#012 bool biswindowsxporlater = (osvi. dwmajorversion> 5) |
#013 (osvi. dwmajorversion = 5) & (osvi. dwminorversion> = 1 ));
#014
#015 // display the current version.
#016 if (biswindowsxporlater)
#017 {
#018 outputdebugstring (_ T ("Windows XP or an updated version! /R/N "));
#019}
#020 else
#021 {
#022 outputdebugstring (_ T ("earlier Windows XP version! /R/N "));
#023}
#024}