Get rid of deprecated warnings for ::GetVersionEx().

This does not solve the actual problem of this function not returning the
correct value for Windows 8+ any more, but at least allows to compile the
library without warnings with MSVC 12 and later.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76400 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-04-27 22:38:37 +00:00
parent 97043cef22
commit 58d654b57c

View File

@@ -1162,25 +1162,49 @@ wxLoadUserResource(const wxString& resourceName,
// OS version // OS version
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
namespace
{
// Helper function wrapping Windows GetVersionEx() which is deprecated since
// Windows 8. For now, all we do in this wrapper is to avoid the deprecation
// warnings but this is not enough as the function now actually doesn't return
// the correct value any more and we need to use VerifyVersionInfo() to perform
// binary search to find the real Windows version.
OSVERSIONINFOEX wxGetWindowsVersionInfo()
{
OSVERSIONINFOEX info;
wxZeroMemory(info);
#ifdef __VISUALC__
#pragma warning(push)
#pragma warning(disable:4996) // 'xxx': was declared deprecated
#endif
info.dwOSVersionInfoSize = sizeof(info);
if ( !::GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&info)) )
{
// This really shouldn't ever happen.
wxFAIL_MSG( "GetVersionEx() unexpectedly failed" );
}
#ifdef __VISUALC__
#pragma warning(pop)
#endif
return info;
}
// check if we're running under a server or workstation Windows system: it // check if we're running under a server or workstation Windows system: it
// returns true or false with obvious meaning as well as -1 if the system type // returns true or false with obvious meaning as well as -1 if the system type
// couldn't be determined // couldn't be determined
// //
// this function is currently private but we may want to expose it later if // this function is currently private but we may want to expose it later if
// it's really useful // it's really useful
namespace
{
int wxIsWindowsServer() int wxIsWindowsServer()
{ {
#ifdef VER_NT_WORKSTATION #ifdef VER_NT_WORKSTATION
OSVERSIONINFOEX info; switch ( wxGetWindowsVersionInfo().wProductType )
wxZeroMemory(info);
info.dwOSVersionInfoSize = sizeof(info);
if ( ::GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&info)) )
{
switch ( info.wProductType )
{ {
case VER_NT_WORKSTATION: case VER_NT_WORKSTATION:
return false; return false;
@@ -1189,7 +1213,6 @@ int wxIsWindowsServer()
case VER_NT_DOMAIN_CONTROLLER: case VER_NT_DOMAIN_CONTROLLER:
return true; return true;
} }
}
#endif // VER_NT_WORKSTATION #endif // VER_NT_WORKSTATION
return -1; return -1;
@@ -1201,12 +1224,7 @@ wxString wxGetOsDescription()
{ {
wxString str; wxString str;
OSVERSIONINFO info; const OSVERSIONINFOEX info = wxGetWindowsVersionInfo();
wxZeroMemory(info);
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if ( ::GetVersionEx(&info) )
{
switch ( info.dwPlatformId ) switch ( info.dwPlatformId )
{ {
#ifdef VER_PLATFORM_WIN32_CE #ifdef VER_PLATFORM_WIN32_CE
@@ -1336,11 +1354,6 @@ wxString wxGetOsDescription()
str << _(", 64-bit edition"); str << _(", 64-bit edition");
break; break;
} }
}
else
{
wxFAIL_MSG( wxT("GetVersionEx() failed") ); // should never happen
}
return str; return str;
} }
@@ -1374,8 +1387,7 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
{ {
static struct static struct
{ {
// this may be false, true or -1 if we tried to initialize but failed bool initialized;
int initialized;
wxOperatingSystemId os; wxOperatingSystemId os;
@@ -1386,11 +1398,8 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
// query the OS info only once as it's not supposed to change // query the OS info only once as it's not supposed to change
if ( !s_version.initialized ) if ( !s_version.initialized )
{ {
OSVERSIONINFO info; const OSVERSIONINFOEX info = wxGetWindowsVersionInfo();
wxZeroMemory(info);
info.dwOSVersionInfoSize = sizeof(info);
if ( ::GetVersionEx(&info) )
{
s_version.initialized = true; s_version.initialized = true;
#if defined(__WXWINCE__) #if defined(__WXWINCE__)
@@ -1413,22 +1422,12 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
s_version.verMaj = info.dwMajorVersion; s_version.verMaj = info.dwMajorVersion;
s_version.verMin = info.dwMinorVersion; s_version.verMin = info.dwMinorVersion;
} }
else // GetVersionEx() failed
{
s_version.initialized = -1;
}
}
if ( s_version.initialized == 1 )
{
if ( verMaj ) if ( verMaj )
*verMaj = s_version.verMaj; *verMaj = s_version.verMaj;
if ( verMin ) if ( verMin )
*verMin = s_version.verMin; *verMin = s_version.verMin;
}
// this works even if we were not initialized successfully as the initial
// values of this field is 0 which is wxOS_UNKNOWN and exactly what we need
return s_version.os; return s_version.os;
} }