VirtualBox

Changeset 35863 in vbox


Ignore:
Timestamp:
Feb 7, 2011 10:59:08 AM (14 years ago)
Author:
vboxsync
Message:

VBoxTray: New startup code, more detailed VBoxTray status-to-host reporting, cleaned up error handling, some renaming.

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

Legend:

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

    r34025 r35863  
    44
    55/*
    6  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2011 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1919
    2020#include <iprt/string.h>
     21#include <VBox/Log.h>
    2122#include <VBox/VBoxGuestLib.h>
    2223
     
    2728
    2829
     30int hlpReportStatus(VBoxGuestStatusCurrent statusCurrent)
     31{
     32    int rc = VbglR3ReportAdditionsStatus(VBoxGuestStatusFacility_VBoxTray,
     33                                         statusCurrent,
     34                                         0 /* Flags */);
     35    if (RT_FAILURE(rc))
     36        Log(("VBoxTray: Could not report VBoxTray status \"%ld\", rc=%Rrc\n", statusCurrent, rc));
     37    return rc;
     38}
    2939
    3040/**
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h

    r34025 r35863  
    2727#endif /* !DEBUG_DISPLAY_CHANGE */
    2828
     29extern int hlpReportStatus(VBoxGuestStatusCurrent statusCurrent);
    2930extern void hlpReloadCursor(void);
    3031extern void hlpResizeRect(RECTL *paRects, unsigned nRects, unsigned uPrimary, unsigned uResized, int iNewWidth, int iNewHeight);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp

    r34026 r35863  
    5151                                                "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
    5252
    53                 rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON,
     53                rc = hlpShowBalloonTip(ghInstance, ghwndToolWindow, ID_TRAYICON,
    5454                                       szMsg, szTitle,
    5555                                       5000 /* Time to display in msec */, NIIF_INFO);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp

    r34382 r35863  
    130130    if (RT_SUCCESS(rc))
    131131    {
    132         hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON,
     132        hlpShowBalloonTip(ghInstance, ghwndToolWindow, ID_TRAYICON,
    133133                          msg.szContent, msg.szTitle,
    134134                          msg.ulShowMS, msg.ulType);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxRestore.cpp

    r33966 r35863  
    130130            /* did we get the right event? */
    131131            if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_RESTORED)
    132                 PostMessage(gToolWindow, WM_VBOXTRAY_VM_RESTORED, 0, 0);
     132                PostMessage(ghwndToolWindow, WM_VBOXTRAY_VM_RESTORED, 0, 0);
    133133            else
    134134                /** @todo Don't poll, but wait for connect/disconnect events */
    135                 PostMessage(gToolWindow, WM_VBOXTRAY_VRDP_CHECK, 0, 0);
     135                PostMessage(ghwndToolWindow, WM_VBOXTRAY_VRDP_CHECK, 0, 0);
    136136        }
    137137        else
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp

    r35304 r35863  
    341341                                    Log(("VBoxTray: SystemParametersInfo SPI_SETSCREENSAVEACTIVE failed with %d\n", GetLastError()));
    342342                            }
    343                             PostMessage(gToolWindow, WM_VBOX_REMOVE_SEAMLESS_HOOK, 0, 0);
     343                            PostMessage(ghwndToolWindow, WM_VBOX_REMOVE_SEAMLESS_HOOK, 0, 0);
    344344                            break;
    345345
     
    355355                            if (!ret)
    356356                                Log(("VBoxTray: SystemParametersInfo SPI_SETSCREENSAVEACTIVE failed with %d\n", GetLastError()));
    357                             PostMessage(gToolWindow, WM_VBOX_INSTALL_SEAMLESS_HOOK, 0, 0);
     357                            PostMessage(ghwndToolWindow, WM_VBOX_INSTALL_SEAMLESS_HOOK, 0, 0);
    358358                            break;
    359359
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r34080 r35863  
    44
    55/*
    6  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2011 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4343*   Global Variables                                                           *
    4444*******************************************************************************/
    45 HANDLE                gVBoxDriver;
    46 HANDLE                gStopSem;
     45HANDLE                ghVBoxDriver;
     46HANDLE                ghStopSem;
    4747HANDLE                ghSeamlessNotifyEvent = 0;
    4848SERVICE_STATUS        gVBoxServiceStatus;
    4949SERVICE_STATUS_HANDLE gVBoxServiceStatusHandle;
    50 HINSTANCE             gInstance;
    51 HWND                  gToolWindow;
     50HINSTANCE             ghInstance;
     51HWND                  ghwndToolWindow;
    5252NOTIFYICONDATA        gNotifyIconData;
    5353DWORD                 gMajorVersion;
     
    141141static int vboxTrayCreateTrayIcon(void)
    142142{
    143     HICON hIcon = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX));
     143    HICON hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX));
    144144    if (hIcon == NULL)
    145145    {
     
    152152    RT_ZERO(gNotifyIconData);
    153153    gNotifyIconData.cbSize           = NOTIFYICONDATA_V1_SIZE; // sizeof(NOTIFYICONDATA);
    154     gNotifyIconData.hWnd             = gToolWindow;
     154    gNotifyIconData.hWnd             = ghwndToolWindow;
    155155    gNotifyIconData.uID              = ID_TRAYICON;
    156156    gNotifyIconData.uFlags           = NIF_ICON | NIF_MESSAGE | NIF_TIP;
     
    289289}
    290290
    291 int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
     291static int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
    292292{
    293293    int rc = VINF_SUCCESS;
     
    312312}
    313313
    314 bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
    315                                   WPARAM wParam, LPARAM lParam)
     314static bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
     315                                         WPARAM wParam, LPARAM lParam)
    316316{
    317317    if (pTable == NULL)
    318318        return false;
    319     while (pTable->pszName)
     319    while (pTable && pTable->pszName)
    320320    {
    321321        if (pTable->uMsgID == uMsg)
     
    332332}
    333333
    334 void WINAPI VBoxServiceStart(void)
    335 {
    336     Log(("VBoxTray: Entering service main function\n"));
    337 
    338     VBOXSERVICEENV svcEnv;
    339     DWORD dwErr = NO_ERROR;
    340 
     334static int vboxTrayOpenBaseDriver()
     335{
    341336    /* Open VBox guest driver. */
    342     gVBoxDriver = CreateFile(VBOXGUEST_DEVICE_NAME,
     337    DWORD dwErr = ERROR_SUCCESS;
     338    ghVBoxDriver = CreateFile(VBOXGUEST_DEVICE_NAME,
    343339                             GENERIC_READ | GENERIC_WRITE,
    344340                             FILE_SHARE_READ | FILE_SHARE_WRITE,
     
    347343                             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
    348344                             NULL);
    349     if (gVBoxDriver == INVALID_HANDLE_VALUE)
     345    if (ghVBoxDriver == INVALID_HANDLE_VALUE)
    350346    {
    351347        dwErr = GetLastError();
    352348        LogRel(("VBoxTray: Could not open VirtualBox Guest Additions driver! Please install / start it first! Error = %08X\n", dwErr));
    353349    }
    354 
    355     if (dwErr == NO_ERROR)
    356     {
    357         /* Create a custom window class. */
    358         WNDCLASS windowClass = {0};
    359         windowClass.style         = CS_NOCLOSE;
    360         windowClass.lpfnWndProc   = (WNDPROC)VBoxToolWndProc;
    361         windowClass.hInstance     = gInstance;
    362         windowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    363         windowClass.lpszClassName = "VBoxTrayToolWndClass";
    364         if (!RegisterClass(&windowClass))
    365         {
    366             dwErr = GetLastError();
    367             Log(("VBoxTray: Registering invisible tool window failed, error = %08X\n", dwErr));
    368         }
    369     }
    370 
    371     if (dwErr == NO_ERROR)
    372     {
    373         /* Create our (invisible) tool window. */
    374         /* Note: The window name ("VBoxTrayToolWnd") and class ("VBoxTrayToolWndClass") is
     350    return RTErrConvertFromWin32(dwErr);
     351}
     352
     353static void vboxTrayCloseBaseDriver()
     354{
     355    if (ghVBoxDriver)
     356    {
     357        CloseHandle(ghVBoxDriver);
     358        ghVBoxDriver = NULL;
     359    }
     360}
     361
     362static void vboxTrayDestroyToolWindow()
     363{
     364    if (ghwndToolWindow)
     365    {
     366        Log(("VBoxTray: Destroying tool window ...\n"));
     367
     368        /* Destroy the tool window. */
     369        DestroyWindow(ghwndToolWindow);
     370        ghwndToolWindow = NULL;
     371
     372        UnregisterClass("VBoxTrayToolWndClass", ghInstance);
     373    }
     374}
     375
     376static int vboxTrayCreateToolWindow()
     377{
     378    DWORD dwErr = ERROR_SUCCESS;
     379
     380    /* Create a custom window class. */
     381    WNDCLASS windowClass = {0};
     382    windowClass.style         = CS_NOCLOSE;
     383    windowClass.lpfnWndProc   = (WNDPROC)VBoxToolWndProc;
     384    windowClass.hInstance     = ghInstance;
     385    windowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
     386    windowClass.lpszClassName = "VBoxTrayToolWndClass";
     387    if (!RegisterClass(&windowClass))
     388    {
     389        dwErr = GetLastError();
     390        Log(("VBoxTray: Registering invisible tool window failed, error = %08X\n", dwErr));
     391    }
     392    else
     393    {
     394        /*
     395         * Create our (invisible) tool window.
     396         * Note: The window name ("VBoxTrayToolWnd") and class ("VBoxTrayToolWndClass") is
    375397         * needed for posting globally registered messages to VBoxTray and must not be
    376          * changed! Otherwise things get broken! */
    377         gToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
    378                                      "VBoxTrayToolWndClass", "VBoxTrayToolWnd",
    379                                      WS_POPUPWINDOW,
    380                                      -200, -200, 100, 100, NULL, NULL, gInstance, NULL);
    381         if (!gToolWindow)
     398         * changed! Otherwise things get broken!
     399         *
     400         */
     401        ghwndToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
     402                                         "VBoxTrayToolWndClass", "VBoxTrayToolWnd",
     403                                         WS_POPUPWINDOW,
     404                                         -200, -200, 100, 100, NULL, NULL, ghInstance, NULL);
     405        if (!ghwndToolWindow)
    382406        {
    383407            dwErr = GetLastError();
     
    386410        else
    387411        {
     412            /* Reload the cursor(s). */
    388413            hlpReloadCursor();
    389         }
    390     }
    391 
    392     Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, dwErr));
    393 
     414
     415            Log(("VBoxTray: Invisible tool window handle = %p\n", ghwndToolWindow));
     416        }
     417    }
     418
     419    if (dwErr != ERROR_SUCCESS)
     420         vboxTrayDestroyToolWindow();
     421    return RTErrConvertFromWin32(dwErr);
     422}
     423
     424static int vboxTraySetupSeamless()
     425{
    394426    OSVERSIONINFO info;
    395     gMajorVersion = 5; /* default XP */
     427    gMajorVersion = 5; /* Default to Windows XP. */
    396428    info.dwOSVersionInfoSize = sizeof(info);
    397429    if (GetVersionEx(&info))
     
    401433    }
    402434
    403     if (dwErr == NO_ERROR)
    404     {
    405         gStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
    406         if (gStopSem == NULL)
    407         {
    408             Log(("VBoxTray: CreateEvent for stopping VBoxTray failed, error = %08X\n", GetLastError()));
    409             return;
    410         }
    411 
    412         /* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore */
    413         SECURITY_ATTRIBUTES     SecAttr;
    414         char                    secDesc[SECURITY_DESCRIPTOR_MIN_LENGTH];
    415         BOOL                    ret;
    416 
    417         SecAttr.nLength              = sizeof(SecAttr);
    418         SecAttr.bInheritHandle       = FALSE;
    419         SecAttr.lpSecurityDescriptor = &secDesc;
    420         InitializeSecurityDescriptor(SecAttr.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
    421         ret = SetSecurityDescriptorDacl(SecAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
    422         if (!ret)
    423             Log(("VBoxTray: SetSecurityDescriptorDacl failed with error = %08X\n", GetLastError()));
    424 
    425         /* For Vista and up we need to change the integrity of the security descriptor too */
     435    /* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore. */
     436    SECURITY_ATTRIBUTES     SecAttr;
     437    DWORD                   dwErr = ERROR_SUCCESS;
     438    char                    secDesc[SECURITY_DESCRIPTOR_MIN_LENGTH];
     439    BOOL                    fRC;
     440
     441    SecAttr.nLength              = sizeof(SecAttr);
     442    SecAttr.bInheritHandle       = FALSE;
     443    SecAttr.lpSecurityDescriptor = &secDesc;
     444    InitializeSecurityDescriptor(SecAttr.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
     445    fRC = SetSecurityDescriptorDacl(SecAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
     446    if (!fRC)
     447    {
     448        dwErr = GetLastError();
     449        Log(("VBoxTray: SetSecurityDescriptorDacl failed with last error = %08X\n", dwErr));
     450    }
     451    else
     452    {
     453        /* For Vista and up we need to change the integrity of the security descriptor, too. */
    426454        if (gMajorVersion >= 6)
    427455        {
    428             HMODULE hModule;
    429 
    430456            BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR  *SecurityDescriptor, PULONG  SecurityDescriptorSize);
    431457
    432             hModule = LoadLibrary("ADVAPI32.DLL");
    433             if (hModule)
     458            HMODULE hModule = LoadLibrary("ADVAPI32.DLL");
     459            if (!hModule)
     460            {
     461                dwErr = GetLastError();
     462                Log(("VBoxTray: Loading module ADVAPI32.DLL failed with last error = %08X\n", dwErr));
     463            }
     464            else
    434465            {
    435466                PSECURITY_DESCRIPTOR    pSD;
     
    443474                if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA)
    444475                {
    445                     ret = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
     476                    fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
    446477                                                                                  SDDL_REVISION_1, &pSD, NULL);
    447                     if (!ret)
    448                         Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with error = %08X\n", GetLastError()));
    449 
    450                     ret = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
    451                     if (!ret)
    452                         Log(("VBoxTray: GetSecurityDescriptorSacl failed with error = %08X\n", GetLastError()));
    453 
    454                     ret = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
    455                     if (!ret)
    456                         Log(("VBoxTray: SetSecurityDescriptorSacl failed with error = %08X\n", GetLastError()));
     478                    if (!fRC)
     479                    {
     480                        dwErr = GetLastError();
     481                        Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with last error = %08X\n", dwErr));
     482                    }
     483                    else
     484                    {
     485                        fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
     486                        if (!fRC)
     487                        {
     488                            dwErr = GetLastError();
     489                            Log(("VBoxTray: GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
     490                        }
     491                        else
     492                        {
     493                            fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
     494                            if (!fRC)
     495                            {
     496                                dwErr = GetLastError();
     497                                Log(("VBoxTray: SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
     498                            }
     499                        }
     500                    }
    457501                }
    458502            }
    459503        }
    460504
    461         if (gMajorVersion >= 5)        /* Only for W2K and up ... */
     505        if (   dwErr == ERROR_SUCCESS
     506            && gMajorVersion >= 5) /* Only for W2K and up ... */
    462507        {
    463508            ghSeamlessNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
    464509            if (ghSeamlessNotifyEvent == NULL)
    465510            {
    466                 Log(("VBoxTray: CreateEvent for Seamless failed, error = %08X\n", GetLastError()));
    467                 return;
    468             }
    469         }
    470     }
    471 
    472     /*
    473      * Start services listed in the vboxServiceTable.
    474      */
    475     svcEnv.hInstance  = gInstance;
    476     svcEnv.hDriver    = gVBoxDriver;
    477 
    478     /* initializes disp-if to default (XPDM) mode */
    479     dwErr = VBoxDispIfInit(&svcEnv.dispIf);
    480 #ifdef VBOX_WITH_WDDM
    481     /*
    482      * For now the display mode will be adjusted to WDDM mode if needed
    483      * on display service initialization when it detects the display driver type.
    484      */
    485 #endif
    486 
    487     if (dwErr == NO_ERROR)
    488     {
    489         int rc = vboxTrayStartServices(&svcEnv, vboxServiceTable);
    490         if (RT_FAILURE (rc))
    491         {
    492             dwErr = ERROR_GEN_FAILURE;
    493         }
    494     }
    495 
    496     /* terminate service if something went wrong */
    497     if (dwErr != NO_ERROR)
    498     {
    499         vboxTrayStopServices(&svcEnv, vboxServiceTable);
    500         return;
    501     }
    502 
    503     int rc = vboxTrayCreateTrayIcon();
    504     if (   RT_SUCCESS(rc)
    505         && gMajorVersion >= 5) /* Only for W2K and up ... */
    506     {
    507         /* We're ready to create the tooltip balloon. */
    508         /* Check in 10 seconds (@todo make seconds configurable) ... */
    509         SetTimer(gToolWindow,
    510                  TIMERID_VBOXTRAY_CHECK_HOSTVERSION,
    511                  10 * 1000, /* 10 seconds */
    512                  NULL       /* No timerproc */);
    513     }
    514 
    515     /* Do the Shared Folders auto-mounting stuff. */
    516     VBoxSharedFoldersAutoMount();
    517 
    518     /* Boost thread priority to make sure we wake up early for seamless window notifications (not sure if it actually makes any difference though) */
    519     SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
    520 
    521     /*
    522      * Main execution loop
    523      * Wait for the stop semaphore to be posted or a window event to arrive
    524      */
    525 
    526     DWORD dwEventCount = 2;
    527     HANDLE hWaitEvent[2] = {gStopSem, ghSeamlessNotifyEvent};
    528 
    529     if (0 == ghSeamlessNotifyEvent)         /* If seamless mode is not active / supported, reduce event array count */
    530         dwEventCount = 1;
    531 
    532     Log(("VBoxTray: Number of events to wait in main loop: %ld\n", dwEventCount));
    533     while (true)
    534     {
    535         DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0);
    536         waitResult = waitResult - WAIT_OBJECT_0;
    537 
    538         /* Only enable for message debugging, lots of traffic! */
    539         //Log(("VBoxTray: Wait result  = %ld\n", waitResult));
    540 
    541         if (waitResult == 0)
    542         {
    543             Log(("VBoxTray: Event 'Exit' triggered\n"));
    544             /* exit */
    545             break;
    546         }
    547         else if (   (waitResult == 1)
    548                  && (ghSeamlessNotifyEvent!=0)) /* Only jump in, if seamless is active! */
    549         {
    550             Log(("VBoxTray: Event 'Seamless' triggered\n"));
    551 
    552             /* seamless window notification */
    553             VBoxSeamlessCheckWindows();
     511                dwErr = GetLastError();
     512                Log(("VBoxTray: CreateEvent for Seamless failed, last error = %08X\n", dwErr));
     513            }
     514        }
     515    }
     516    return RTErrConvertFromWin32(dwErr);
     517}
     518
     519static void vboxTrayShutdownSeamless(void)
     520{
     521        if (ghSeamlessNotifyEvent)
     522        {
     523        CloseHandle(ghSeamlessNotifyEvent);
     524            ghSeamlessNotifyEvent = NULL;
     525        }
     526}
     527
     528static int vboxTrayServiceMain(void)
     529{
     530    int rc = VINF_SUCCESS;
     531    Log(("VBoxTray: Entering vboxTrayServiceMain\n"));
     532
     533    ghStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
     534    if (ghStopSem == NULL)
     535    {
     536        rc = RTErrConvertFromWin32(GetLastError());
     537        Log(("VBoxTray: CreateEvent for stopping VBoxTray failed, rc=%Rrc\n", rc));
     538    }
     539    else
     540    {
     541        /*
     542         * Start services listed in the vboxServiceTable.
     543         */
     544        VBOXSERVICEENV svcEnv;
     545        svcEnv.hInstance = ghInstance;
     546        svcEnv.hDriver   = ghVBoxDriver;
     547
     548        /* Initializes disp-if to default (XPDM) mode. */
     549        VBoxDispIfInit(&svcEnv.dispIf); /* Cannot fail atm. */
     550    #ifdef VBOX_WITH_WDDM
     551        /*
     552         * For now the display mode will be adjusted to WDDM mode if needed
     553         * on display service initialization when it detects the display driver type.
     554         */
     555    #endif
     556
     557        /* Finally start all the built-in services! */
     558        rc = vboxTrayStartServices(&svcEnv, vboxServiceTable);
     559        if (RT_FAILURE(rc))
     560        {
     561            /* Terminate service if something went wrong. */
     562            vboxTrayStopServices(&svcEnv, vboxServiceTable);
    554563        }
    555564        else
    556565        {
    557             /* timeout or a window message, handle it */
    558             MSG msg;
    559             while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    560             {
    561                 Log(("VBoxTray: msg %p\n", msg.message));
    562                 if (msg.message == WM_QUIT)
     566            rc = vboxTrayCreateTrayIcon();
     567            if (   RT_SUCCESS(rc)
     568                && gMajorVersion >= 5) /* Only for W2K and up ... */
     569            {
     570                /* We're ready to create the tooltip balloon.
     571                   Check in 10 seconds (@todo make seconds configurable) ... */
     572                SetTimer(ghwndToolWindow,
     573                         TIMERID_VBOXTRAY_CHECK_HOSTVERSION,
     574                         10 * 1000, /* 10 seconds */
     575                         NULL       /* No timerproc */);
     576            }
     577
     578            if (RT_SUCCESS(rc))
     579            {
     580                /* Do the Shared Folders auto-mounting stuff. */
     581                rc = VBoxSharedFoldersAutoMount();
     582                if (RT_SUCCESS(rc))
    563583                {
    564                     Log(("VBoxTray: WM_QUIT!\n"));
    565                     SetEvent(gStopSem);
    566                     continue;
     584                    /* Report the host that we're up and running! */
     585                    rc = hlpReportStatus(VBoxGuestStatusCurrent_Active);
    567586                }
    568                 TranslateMessage(&msg);
    569                 DispatchMessage(&msg);
    570             }
    571         }
    572     }
    573 
    574     Log(("VBoxTray: Returned from main loop, exiting ...\n"));
     587            }
     588
     589            if (RT_SUCCESS(rc))
     590            {
     591                /* Boost thread priority to make sure we wake up early for seamless window notifications
     592                 * (not sure if it actually makes any difference though). */
     593                SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
     594
     595                /*
     596                 * Main execution loop
     597                 * Wait for the stop semaphore to be posted or a window event to arrive
     598                 */
     599
     600                DWORD dwEventCount = 2;
     601                HANDLE hWaitEvent[2] = { ghStopSem, ghSeamlessNotifyEvent };
     602
     603                if (0 == ghSeamlessNotifyEvent) /* If seamless mode is not active / supported, reduce event array count. */
     604                    dwEventCount = 1;
     605
     606                Log(("VBoxTray: Number of events to wait in main loop: %ld\n", dwEventCount));
     607                while (true)
     608                {
     609                    DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0);
     610                    waitResult = waitResult - WAIT_OBJECT_0;
     611
     612                    /* Only enable for message debugging, lots of traffic! */
     613                    //Log(("VBoxTray: Wait result  = %ld\n", waitResult));
     614
     615                    if (waitResult == 0)
     616                    {
     617                        Log(("VBoxTray: Event 'Exit' triggered\n"));
     618                        /* exit */
     619                        break;
     620                    }
     621                    else if (   waitResult == 1
     622                             && ghSeamlessNotifyEvent != 0) /* Only jump in, if seamless is active! */
     623                    {
     624                        Log(("VBoxTray: Event 'Seamless' triggered\n"));
     625
     626                        /* seamless window notification */
     627                        VBoxSeamlessCheckWindows();
     628                    }
     629                    else
     630                    {
     631                        /* timeout or a window message, handle it */
     632                        MSG msg;
     633                        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
     634                        {
     635                            Log(("VBoxTray: msg %p\n", msg.message));
     636                            if (msg.message == WM_QUIT)
     637                            {
     638                                Log(("VBoxTray: WM_QUIT!\n"));
     639                                SetEvent(ghStopSem);
     640                                continue;
     641                            }
     642                            TranslateMessage(&msg);
     643                            DispatchMessage(&msg);
     644                        }
     645                    }
     646                }
     647                Log(("VBoxTray: Returned from main loop, exiting ...\n"));
     648            }
     649            Log(("VBoxTray: Waiting for services to stop ...\n"));
     650            vboxTrayStopServices(&svcEnv, vboxServiceTable);
     651        } /* Services started */
     652        CloseHandle(ghStopSem);
     653    } /* Stop event created */
    575654
    576655    vboxTrayRemoveTrayIcon();
    577656
    578     Log(("VBoxTray: Waiting for display change thread ...\n"));
    579 
    580     vboxTrayStopServices(&svcEnv, vboxServiceTable);
    581 
    582     Log(("VBoxTray: Destroying tool window ...\n"));
    583 
    584     /* Destroy the tool window. */
    585     DestroyWindow(gToolWindow);
    586 
    587     UnregisterClass("VBoxTrayToolWndClass", gInstance);
    588 
    589     CloseHandle(gVBoxDriver);
    590     CloseHandle(gStopSem);
    591     CloseHandle(ghSeamlessNotifyEvent);
    592 
    593     Log(("VBoxTray: Leaving service main function\n"));
    594 
    595     return;
    596 }
    597 
     657    Log(("VBoxTray: Leaving vboxTrayServiceMain with rc=%Rrc\n", rc));
     658    return rc;
     659}
    598660
    599661/**
     
    613675    }
    614676
     677    LogRel(("VBoxTray: %s r%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr()));
     678
    615679    int rc = RTR3Init();
     680    if (RT_SUCCESS(rc))
     681    {
     682        rc = VbglR3Init();
     683        if (RT_SUCCESS(rc))
     684            rc = vboxTrayOpenBaseDriver();
     685    }
     686
    616687    if (RT_FAILURE(rc))
    617         return rc;
    618 
    619     rc = VbglR3Init();
    620     if (RT_FAILURE(rc))
    621         return rc;
    622 
    623     LogRel(("VBoxTray: %s r%s started\n", RTBldCfgVersion(), RTBldCfgRevisionStr()));
    624 
    625     gInstance = hInstance;
    626     VBoxServiceStart();
    627 
     688    {
     689        CloseHandle (hMutexAppRunning);
     690        hMutexAppRunning = NULL;
     691        return 1;
     692    }
     693
     694    if (RT_SUCCESS(rc))
     695    {
     696        /* Save instance handle. */
     697        ghInstance = hInstance;
     698
     699        rc = hlpReportStatus(VBoxGuestStatusCurrent_Init);
     700        if (RT_SUCCESS(rc))
     701        {
     702            rc = vboxTrayCreateToolWindow();
     703            if (RT_SUCCESS(rc))
     704            {
     705                rc = vboxTraySetupSeamless();
     706                if (RT_SUCCESS(rc))
     707                {
     708                    Log(("VBoxTray: Init successful\n"));
     709                    rc = vboxTrayServiceMain();
     710                    hlpReportStatus(VBoxGuestStatusCurrent_Terminating);
     711                    vboxTrayShutdownSeamless();
     712                }
     713                vboxTrayDestroyToolWindow();
     714            }
     715            rc = hlpReportStatus(VBoxGuestStatusCurrent_Inactive);
     716        }
     717    }
     718    else
     719        Log(("VBoxTray: Could not report VBoxTray status \"Init\", rc=%Rrc\n", rc));
     720        if (RT_FAILURE(rc))
     721        LogRel(("VBoxTray: Error while starting, rc=%Rrc\n", rc));
    628722    LogRel(("VBoxTray: Ended\n"));
    629723
     
    661755        case WM_DESTROY:
    662756            Log(("VBoxTray: Tool window destroyed\n"));
    663             KillTimer(gToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
     757            KillTimer(ghwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
    664758            return 0;
    665759
     
    671765                    {
    672766                        /* After successful run we don't need to check again. */
    673                         KillTimer(gToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
     767                        KillTimer(ghwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
    674768                    }
    675769                    return 0;
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h

    r34080 r35863  
    102102} VBOXGLOBALMESSAGE, *PVBOXGLOBALMESSAGE;
    103103
    104 extern HWND         gToolWindow;
    105 extern HINSTANCE    gInstance;
     104extern HWND         ghwndToolWindow;
     105extern HINSTANCE    ghInstance;
    106106
    107107#endif /* !___VBOXTRAY_H */
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