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:
@@ -1162,25 +1162,49 @@ wxLoadUserResource(const wxString& resourceName,
|
||||
// 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
|
||||
// returns true or false with obvious meaning as well as -1 if the system type
|
||||
// couldn't be determined
|
||||
//
|
||||
// this function is currently private but we may want to expose it later if
|
||||
// it's really useful
|
||||
namespace
|
||||
{
|
||||
|
||||
int wxIsWindowsServer()
|
||||
{
|
||||
#ifdef VER_NT_WORKSTATION
|
||||
OSVERSIONINFOEX info;
|
||||
wxZeroMemory(info);
|
||||
|
||||
info.dwOSVersionInfoSize = sizeof(info);
|
||||
if ( ::GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&info)) )
|
||||
{
|
||||
switch ( info.wProductType )
|
||||
switch ( wxGetWindowsVersionInfo().wProductType )
|
||||
{
|
||||
case VER_NT_WORKSTATION:
|
||||
return false;
|
||||
@@ -1189,7 +1213,6 @@ int wxIsWindowsServer()
|
||||
case VER_NT_DOMAIN_CONTROLLER:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif // VER_NT_WORKSTATION
|
||||
|
||||
return -1;
|
||||
@@ -1201,12 +1224,7 @@ wxString wxGetOsDescription()
|
||||
{
|
||||
wxString str;
|
||||
|
||||
OSVERSIONINFO info;
|
||||
wxZeroMemory(info);
|
||||
|
||||
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
if ( ::GetVersionEx(&info) )
|
||||
{
|
||||
const OSVERSIONINFOEX info = wxGetWindowsVersionInfo();
|
||||
switch ( info.dwPlatformId )
|
||||
{
|
||||
#ifdef VER_PLATFORM_WIN32_CE
|
||||
@@ -1336,11 +1354,6 @@ wxString wxGetOsDescription()
|
||||
str << _(", 64-bit edition");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxFAIL_MSG( wxT("GetVersionEx() failed") ); // should never happen
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -1374,8 +1387,7 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
|
||||
{
|
||||
static struct
|
||||
{
|
||||
// this may be false, true or -1 if we tried to initialize but failed
|
||||
int initialized;
|
||||
bool initialized;
|
||||
|
||||
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
|
||||
if ( !s_version.initialized )
|
||||
{
|
||||
OSVERSIONINFO info;
|
||||
wxZeroMemory(info);
|
||||
info.dwOSVersionInfoSize = sizeof(info);
|
||||
if ( ::GetVersionEx(&info) )
|
||||
{
|
||||
const OSVERSIONINFOEX info = wxGetWindowsVersionInfo();
|
||||
|
||||
s_version.initialized = true;
|
||||
|
||||
#if defined(__WXWINCE__)
|
||||
@@ -1413,22 +1422,12 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
|
||||
s_version.verMaj = info.dwMajorVersion;
|
||||
s_version.verMin = info.dwMinorVersion;
|
||||
}
|
||||
else // GetVersionEx() failed
|
||||
{
|
||||
s_version.initialized = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( s_version.initialized == 1 )
|
||||
{
|
||||
if ( verMaj )
|
||||
*verMaj = s_version.verMaj;
|
||||
if ( 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user