VirtualBox

Changeset 78937 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Jun 3, 2019 1:52:06 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131059
Message:

VBoxTray: Use RTSystemGetNtVersion() rather than GetVersion or GetVersionEx for determining the actual windows version. Some cleanups.

Location:
trunk/src/VBox/Additions/WINNT/VBoxTray
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp

    r76553 r78937  
    1616 */
    1717
     18
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
    1822#include "VBoxTray.h"
    1923#define _WIN32_WINNT 0x0601
     
    2125#include <iprt/errcore.h>
    2226#include <iprt/assert.h>
     27#include <iprt/system.h>
    2328
    2429#include <malloc.h>
     
    644649{
    645650    DWORD err = NO_ERROR;
    646     OSVERSIONINFO OSinfo;
    647     OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
    648     GetVersionEx (&OSinfo);
    649     bool bSupported = true;
    650 
    651     if (OSinfo.dwMajorVersion >= 6)
     651
     652    bool fSupported = true;
     653
     654    uint64_t const uNtVersion = RTSystemGetNtVersion();
     655    if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
    652656    {
    653657        LogFunc(("this is vista and up\n"));
     
    657661            *(uintptr_t *)&pIf->modeData.wddm.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
    658662            LogFunc(("VBoxDisplayInit: pfnChangeDisplaySettingsEx = %p\n", pIf->modeData.wddm.pfnChangeDisplaySettingsEx));
    659             bSupported &= !!(pIf->modeData.wddm.pfnChangeDisplaySettingsEx);
     663            fSupported &= !!(pIf->modeData.wddm.pfnChangeDisplaySettingsEx);
    660664
    661665            *(uintptr_t *)&pIf->modeData.wddm.pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
    662666            LogFunc(("VBoxDisplayInit: pfnEnumDisplayDevices = %p\n", pIf->modeData.wddm.pfnEnumDisplayDevices));
    663             bSupported &= !!(pIf->modeData.wddm.pfnEnumDisplayDevices);
     667            fSupported &= !!(pIf->modeData.wddm.pfnEnumDisplayDevices);
     668
    664669            /* for win 7 and above */
    665              if (OSinfo.dwMinorVersion >= 1)
     670            if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 1, 0))
    666671            {
    667672                *(uintptr_t *)&gCtx.pfnSetDisplayConfig = (uintptr_t)GetProcAddress(hUser, "SetDisplayConfig");
    668673                LogFunc(("VBoxDisplayInit: pfnSetDisplayConfig = %p\n", gCtx.pfnSetDisplayConfig));
    669                 bSupported &= !!(gCtx.pfnSetDisplayConfig);
     674                fSupported &= !!(gCtx.pfnSetDisplayConfig);
    670675
    671676                *(uintptr_t *)&gCtx.pfnQueryDisplayConfig = (uintptr_t)GetProcAddress(hUser, "QueryDisplayConfig");
    672677                LogFunc(("VBoxDisplayInit: pfnQueryDisplayConfig = %p\n", gCtx.pfnQueryDisplayConfig));
    673                 bSupported &= !!(gCtx.pfnQueryDisplayConfig);
     678                fSupported &= !!(gCtx.pfnQueryDisplayConfig);
    674679
    675680                *(uintptr_t *)&gCtx.pfnGetDisplayConfigBufferSizes = (uintptr_t)GetProcAddress(hUser, "GetDisplayConfigBufferSizes");
    676681                LogFunc(("VBoxDisplayInit: pfnGetDisplayConfigBufferSizes = %p\n", gCtx.pfnGetDisplayConfigBufferSizes));
    677                 bSupported &= !!(gCtx.pfnGetDisplayConfigBufferSizes);
     682                fSupported &= !!(gCtx.pfnGetDisplayConfigBufferSizes);
    678683            }
    679684
     
    25292534    DWORD err = NO_ERROR;
    25302535
    2531     OSVERSIONINFO OSinfo;
    2532     OSinfo.dwOSVersionInfoSize = sizeof(OSinfo);
    2533     GetVersionEx (&OSinfo);
    2534     if (OSinfo.dwMajorVersion >= 5)
     2536    uint64_t const uNtVersion = RTSystemGetNtVersion();
     2537    if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0))
    25352538    {
    25362539        HMODULE hUser = GetModuleHandle("user32.dll");
    25372540        if (NULL != hUser)
    25382541        {
    2539             bool bSupported = true;
    25402542            *(uintptr_t *)&pIf->modeData.xpdm.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
    25412543            LogFunc(("pfnChangeDisplaySettingsEx = %p\n", pIf->modeData.xpdm.pfnChangeDisplaySettingsEx));
    2542             bSupported &= !!(pIf->modeData.xpdm.pfnChangeDisplaySettingsEx);
    2543 
    2544             if (!bSupported)
     2544            bool const fSupported = RT_BOOL(pIf->modeData.xpdm.pfnChangeDisplaySettingsEx);
     2545            if (!fSupported)
    25452546            {
    25462547                WARN_FUNC(("pfnChangeDisplaySettingsEx function pointer failed to initialize\n"));
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp

    r76553 r78937  
    2929# include <iprt/asm.h>
    3030#endif
     31#include <iprt/system.h>
    3132
    3233#ifdef DEBUG /** @todo r=bird: these are all default values. sigh. */
     
    8283    AssertPtr(pCtx);
    8384
    84     OSVERSIONINFO OSinfo; /** @todo r=andy Use VBoxTray's g_dwMajorVersion? */
    85     OSinfo.dwOSVersionInfoSize = sizeof(OSinfo);
    86     GetVersionEx (&OSinfo);
    87 
    8885    int rc;
    8986    HMODULE hUser = GetModuleHandle("user32.dll"); /** @todo r=andy Use RTLdrXXX and friends. */
     
    9188    pCtx->pEnv = pEnv;
    9289
     90    uint64_t const uNtVersion = RTSystemGetNtVersion();
     91
    9392    if (NULL == hUser)
    9493    {
     
    9695        rc = VERR_NOT_IMPLEMENTED;
    9796    }
    98     else if (OSinfo.dwMajorVersion >= 5)        /* APIs available only on W2K and up. */
     97    else if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* APIs available only on W2K and up. */
    9998    {
    10099        /** @todo r=andy Use RTLdrXXX and friends. */
     
    107106
    108107#ifdef VBOX_WITH_WDDM
    109         if (OSinfo.dwMajorVersion >= 6)
     108        if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
    110109        {
    111110            /* This is Vista and up, check if we need to switch the display driver if to WDDM mode. */
     
    116115                LogFlowFunc(("WDDM driver is installed, switching display driver if to WDDM mode\n"));
    117116                /* This is hacky, but the most easiest way. */
    118                 VBOXDISPIF_MODE enmMode = (OSinfo.dwMajorVersion == 6 && OSinfo.dwMinorVersion == 0) ? VBOXDISPIF_MODE_WDDM : VBOXDISPIF_MODE_WDDM_W7;
     117                VBOXDISPIF_MODE enmMode = uNtVersion < RTSYSTEM_MAKE_NT_VERSION(6, 1, 0)
     118                                        ? VBOXDISPIF_MODE_WDDM : VBOXDISPIF_MODE_WDDM_W7;
    119119                DWORD dwErr = VBoxDispIfSwitchMode(const_cast<PVBOXDISPIF>(&pEnv->dispIf), enmMode, NULL /* old mode, we don't care about it */);
    120120                if (dwErr == NO_ERROR)
     
    136136#endif
    137137    }
    138     else if (OSinfo.dwMajorVersion <= 4) /* Windows NT 4.0. */
     138    else if (uNtVersion < RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Windows NT 4.0. */
    139139    {
    140140        /* Nothing to do here yet. */
     
    280280                deviceMode.dmPosition.y = 0;
    281281                deviceMode.dmBitsPerPel = 32;
    282                 OSVERSIONINFO OSinfo;
    283                 OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
    284                 GetVersionEx (&OSinfo);
    285 
    286                 if (OSinfo.dwMajorVersion < 6)
     282
     283                uint64_t const uNtVersion = RTSystemGetNtVersion();
     284                if (uNtVersion < RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
    287285                    /* dont any more flags here as, only DM_POISITON is used to enable the secondary display */
    288286                    deviceMode.dmFields = DM_POSITION;
    289287                else /* for win 7 and above */
    290288                    /* for vista and above DM_BITSPERPEL is necessary */
    291                     deviceMode.dmFields =   DM_BITSPERPEL | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY  | DM_POSITION;
     289                    deviceMode.dmFields = DM_BITSPERPEL | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY  | DM_POSITION;
    292290
    293291                dwStatus = pCtx->pfnChangeDisplaySettingsEx((LPSTR)displayDevice.DeviceName,&deviceMode, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp

    r76553 r78937  
    2020#include <iprt/string.h>
    2121#include <iprt/alloca.h>
     22#include <iprt/system.h>
    2223#include <VBox/Log.h>
    2324#include <VBox/VBoxGuestLib.h>
     
    290291    /* Do we want to have */
    291292
    292     /* Get running OS version. */
    293     OSVERSIONINFO osInfo;
    294     osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    295     if (FALSE == GetVersionEx(&osInfo))
    296         return RTErrConvertFromWin32(GetLastError());
    297 
    298293    /* Is the current OS supported (at least WinXP) for displaying
    299294     * our own icon and do we actually *want* to display our own stuff? */
    300     if (   osInfo.dwMajorVersion >= 5
     295    uint64_t const uNtVersion = RTSystemGetNtVersion();
     296    if (    uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)
    301297        && (dwInfoFlags & NIIF_INFO))
    302298    {
     
    306302            niData.dwInfoFlags = NIIF_USER; /* Use an own notification icon. */
    307303
    308         if (   osInfo.dwMajorVersion == 5
    309             && osInfo.dwMinorVersion == 1) /* WinXP. */
     304        if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 1, 0)) /* WinXP. */
    310305        {
    311306            /* Use an own icon instead of the default one. */
    312307            niData.hIcon = hIcon;
    313308        }
    314         else if (osInfo.dwMajorVersion == 6) /* Vista and up. */
     309        else if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0)) /* Vista and up. */
    315310        {
    316311            /* Use an own icon instead of the default one. */
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp

    r76553 r78937  
    2121#include <iprt/assert.h>
    2222#include <iprt/ldr.h>
     23#include <iprt/system.h>
    2324
    2425#include <VBoxDisplay.h>
     
    6970    pCtx->hModHook = NIL_RTLDRMOD;
    7071
    71     OSVERSIONINFO OSinfo;
    72     OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
    73     GetVersionEx (&OSinfo);
    74 
    7572    int rc;
    7673
    7774    /* We have to jump out here when using NT4, otherwise it complains about
    7875       a missing API function "UnhookWinEvent" used by the dynamically loaded VBoxHook.dll below */
    79     if (OSinfo.dwMajorVersion <= 4)         /* Windows NT 4.0 or older */
     76    uint64_t const uNtVersion = RTSystemGetNtVersion();
     77    if (uNtVersion < RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Windows NT 4.0 or older */
    8078    {
    8179        Log(("VBoxTray: VBoxSeamlessInit: Windows NT 4.0 or older not supported!\n"));
     
    214212    char szWindowText[256];
    215213    char szWindowClass[256];
    216     OSVERSIONINFO OSinfo;
    217214    HWND hStart = NULL;
    218215
     
    223220    GetClassName(hwnd, szWindowClass, sizeof(szWindowClass));
    224221
    225     OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
    226     GetVersionEx (&OSinfo);
    227 
    228     if (OSinfo.dwMajorVersion >= 6)
     222    uint64_t const uNtVersion = RTSystemGetNtVersion();
     223    if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
    229224    {
    230225        hStart = ::FindWindowEx(GetDesktopWindow(), NULL, "Button", "Start");
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r78809 r78937  
    142142HWND                  g_hwndToolWindow;
    143143NOTIFYICONDATA        g_NotifyIconData;
    144 DWORD                 g_dwMajorVersion;
    145144
    146145uint32_t              g_fGuestDisplaysChanged = 0;
     
    685684static int vboxTraySetupSeamless(void)
    686685{
    687     OSVERSIONINFO info;
    688     g_dwMajorVersion = 5; /* Default to Windows XP. */
    689     info.dwOSVersionInfoSize = sizeof(info);
    690     if (GetVersionEx(&info))
    691     {
    692         Log(("Windows version %ld.%ld\n", info.dwMajorVersion, info.dwMinorVersion));
    693         g_dwMajorVersion = info.dwMajorVersion;
    694     }
    695 
    696686    /* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore. */
    697687    SECURITY_ATTRIBUTES     SecAttr;
     
    713703    {
    714704        /* For Vista and up we need to change the integrity of the security descriptor, too. */
    715         if (g_dwMajorVersion >= 6)
     705        uint64_t const uNtVersion = RTSystemGetNtVersion();
     706        if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
    716707        {
    717708            BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR  *SecurityDescriptor, PULONG  SecurityDescriptorSize);
     
    755746
    756747        if (   dwErr == ERROR_SUCCESS
    757             && g_dwMajorVersion >= 5) /* Only for W2K and up ... */
     748            && uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Only for W2K and up ... */
    758749        {
    759750            g_hSeamlessWtNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_WT_EVENT_NAME);
     
    837828        else
    838829        {
     830            uint64_t const uNtVersion = RTSystemGetNtVersion();
    839831            rc = vboxTrayCreateTrayIcon();
    840832            if (   RT_SUCCESS(rc)
    841                 && g_dwMajorVersion >= 5) /* Only for W2K and up ... */
     833                && uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Only for W2K and up ... */
    842834            {
    843835                /* We're ready to create the tooltip balloon.
     
    998990        if (RT_SUCCESS(rc))
    999991        {
     992            /* Log the major windows NT version: */
     993            uint64_t const uNtVersion = RTSystemGetNtVersion();
     994            LogRel(("Windows version %u.%u build %u (uNtVersion=%#RX64)\n", RTSYSTEM_NT_VERSION_GET_MAJOR(uNtVersion),
     995                    RTSYSTEM_NT_VERSION_GET_MINOR(uNtVersion), RTSYSTEM_NT_VERSION_GET_BUILD(uNtVersion), uNtVersion ));
     996
    1000997            /* Save instance handle. */
    1001998            g_hInstance = hInstance;
     
    14651462static int vboxDtInit()
    14661463{
    1467     int rc = VINF_SUCCESS;
    1468     OSVERSIONINFO info;
    1469     g_dwMajorVersion = 5; /* Default to Windows XP. */
    1470     info.dwOSVersionInfoSize = sizeof(info);
    1471     if (GetVersionEx(&info))
    1472     {
    1473         LogRel(("Windows version %ld.%ld\n", info.dwMajorVersion, info.dwMinorVersion));
    1474         g_dwMajorVersion = info.dwMajorVersion;
    1475     }
    1476 
    14771464    RT_ZERO(gVBoxDt);
    14781465
     1466    int rc;
    14791467    gVBoxDt.hNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME);
    14801468    if (gVBoxDt.hNotifyEvent != NULL)
     
    15231511                    BOOL fRc = FALSE;
    15241512                    /* For Vista and up we need to change the integrity of the security descriptor, too. */
    1525                     if (g_dwMajorVersion >= 6)
     1513                    uint64_t const uNtVersion = RTSystemGetNtVersion();
     1514                    if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
    15261515                    {
    15271516                        HMODULE hModHook = (HMODULE)RTLdrGetNativeHandle(gVBoxDt.hLdrModHook);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h

    r78809 r78937  
    2222#endif
    2323
    24 #       define _InterlockedExchange           _InterlockedExchange_StupidDDKVsCompilerCrap
    25 #       define _InterlockedExchangeAdd        _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
    26 #       define _InterlockedCompareExchange    _InterlockedCompareExchange_StupidDDKVsCompilerCrap
    27 #       define _InterlockedAddLargeStatistic  _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
    28 #       define _interlockedbittestandset      _interlockedbittestandset_StupidDDKVsCompilerCrap
    29 #       define _interlockedbittestandreset    _interlockedbittestandreset_StupidDDKVsCompilerCrap
    30 #       define _interlockedbittestandset64    _interlockedbittestandset64_StupidDDKVsCompilerCrap
    31 #       define _interlockedbittestandreset64  _interlockedbittestandreset64_StupidDDKVsCompilerCrap
    32 #       pragma warning(disable : 4163)
    3324#include <iprt/win/windows.h>
    34 #       pragma warning(default : 4163)
    35 #       undef  _InterlockedExchange
    36 #       undef  _InterlockedExchangeAdd
    37 #       undef  _InterlockedCompareExchange
    38 #       undef  _InterlockedAddLargeStatistic
    39 #       undef  _interlockedbittestandset
    40 #       undef  _interlockedbittestandreset
    41 #       undef  _interlockedbittestandset64
    42 #       undef  _interlockedbittestandreset64
    4325
    4426#include <tchar.h>
     
    189171} VBOXGLOBALMESSAGE, *PVBOXGLOBALMESSAGE;
    190172
     173extern HINSTANCE    g_hInstance;
    191174extern HWND         g_hwndToolWindow;
    192 extern HINSTANCE    g_hInstance;
    193175extern uint32_t     g_fGuestDisplaysChanged;
    194176
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette