VirtualBox

Ignore:
Timestamp:
Oct 17, 2024 7:44:43 AM (4 months ago)
Author:
vboxsync
Message:

Additions/VBoxTray: Implemented ability for easier user-controllable logging (also via verbose levels), support for running in foreground mode (with a console window attached to) and selective starting of sub services to easier pinpoint errors in release builds. Cleaned up initialization / termination code a little. See command line help for new options. bugref:10763

Location:
trunk/src/VBox/Additions/WINNT/VBoxTray
Files:
1 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk

    r106061 r106411  
    4949VBoxTray_SOURCES  = \
    5050        VBoxTray.cpp \
     51        VBoxTrayLogging.cpp \
    5152        VBoxCaps.cpp \
    5253        VBoxConsole.cpp \
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp

    r106061 r106411  
    3434
    3535#include "VBoxTray.h"
     36#include "VBoxTrayInternal.h"
    3637#include "VBoxHelpers.h"
    3738
     
    6263{
    6364    /** Pointer to the VBoxClient service environment. */
    64     const VBOXSERVICEENV *pEnv;
     65    const VBOXTRAYSVCENV *pEnv;
    6566    /** Command context. */
    6667    VBGLR3SHCLCMDCTX      CmdCtx;
     
    315316
    316317    if (RT_FAILURE(rc))
    317         LogRel(("Shared Clipboard: Starting transfer failed, rc=%Rrc\n", rc));
     318        VBoxTrayError("Shared Clipboard: Starting transfer failed, rc=%Rrc\n", rc);
    318319}
    319320
     
    326327    LogFlowFunc(("rcCompletion=%Rrc\n", rcCompletion));
    327328
    328     LogRel2(("Shared Clipboard: Transfer %RU16 %s\n",
    329              ShClTransferGetID(pCbCtx->pTransfer), rcCompletion == VERR_CANCELLED ? "canceled" : "complete"));
     329    VBoxTrayVerbose(1, "Shared Clipboard: Transfer %RU16 %s\n",
     330                    ShClTransferGetID(pCbCtx->pTransfer), rcCompletion == VERR_CANCELLED ? "canceled" : "complete");
    330331
    331332    SHCLTRANSFERSTATUS enmSts;
     
    356357    AssertPtr(pCtx);
    357358
    358     LogRel(("Shared Clipboard: Transfer %RU16 failed with %Rrc\n", ShClTransferGetID(pCbCtx->pTransfer), rcError));
     359    VBoxTrayError("Shared Clipboard: Transfer %RU16 failed with %Rrc\n", ShClTransferGetID(pCbCtx->pTransfer), rcError);
    359360
    360361    if (g_cVerbosity) /* Only show this in verbose mode. */
     
    368369                    "Transfer %RU16 failed with %Rrc", ShClTransferGetID(pCbCtx->pTransfer), rcError);
    369370
    370         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    371                           szMsg, szTitle,
    372                           5000 /* Time to display in msec */, NIIF_INFO);
     371        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     372                                    szMsg, szTitle,
     373                                    5000 /* Time to display in msec */, NIIF_INFO);
    373374    }
    374375
     
    426427
    427428            if (RT_FAILURE(rc))
    428                 LogRel(("Shared Clipboard: WM_CLIPBOARDUPDATE failed with %Rrc\n", rc));
     429                VBoxTrayError("Shared Clipboard: WM_CLIPBOARDUPDATE failed with %Rrc\n", rc);
    429430
    430431            break;
     
    495496
    496497            LogFunc(("WM_RENDERFORMAT: uFmtWin=%u -> uFmtVBox=0x%x\n", uFmtWin, uFmtVBox));
    497 #ifdef LOG_ENABLED
     498
    498499            char *pszFmts = ShClFormatsToStrA(uFmtVBox);
    499500            AssertPtrReturn(pszFmts, 0);
    500             LogRel(("Shared Clipboard: Rendering Windows format %#x as VBox format '%s'\n", uFmtWin, pszFmts));
     501            VBoxTrayVerbose(1, "Shared Clipboard: Rendering Windows format %#x as VBox format '%s'\n", uFmtWin, pszFmts);
    501502            RTStrFree(pszFmts);
    502 #endif
     503
    503504            if (uFmtVBox == VBOX_SHCL_FMT_NONE)
    504505            {
    505                 LogRel(("Shared Clipboard: Unsupported format (%#x) requested\n", uFmtWin));
     506                VBoxTrayInfo("Shared Clipboard: Unsupported format (%#x) requested\n", uFmtWin);
    506507                ShClWinClear();
    507508            }
     
    523524                            cbData = (uint32_t)((cwcActual + 1 /* '\0' */) * sizeof(RTUTF16));
    524525                        else
    525                             LogRel(("Shared Clipboard: Invalid UTF16 string from host: cb=%RU32, cwcActual=%zu, rc=%Rrc\n",
    526                                     cbData, cwcActual, rc));
     526                            VBoxTrayError("Shared Clipboard: Invalid UTF16 string from host: cb=%RU32, cwcActual=%zu, rc=%Rrc\n",
     527                                          cbData, cwcActual, rc);
    527528                    }
    528529                    else if (uFmtVBox == VBOX_SHCL_FMT_HTML)
     
    549550
    550551                            if (RT_FAILURE(rc))
    551                                 LogRel(("Shared Clipboard: Cannot convert HTML clipboard data into CF_HTML clipboard format, rc=%Rrc\n", rc));
     552                                VBoxTrayError("Shared Clipboard: Cannot convert HTML clipboard data into CF_HTML clipboard format, rc=%Rrc\n", rc);
    552553                        }
    553554                    }
     
    569570                            }
    570571                            else
    571                                 LogRel(("Shared Clipboard: Setting host data buffer to clipboard failed with %Rrc\n",
    572                                         RTErrConvertFromWin32(GetLastError())));
     572                                VBoxTrayError("Shared Clipboard: Setting host data buffer to clipboard failed with %Rrc\n",
     573                                              RTErrConvertFromWin32(GetLastError()));
    573574                        }
    574575                        else
    575                             LogRel(("Shared Clipboard: Failed to lock memory (%Rrc)\n", RTErrConvertFromWin32(GetLastError())));
     576                            VBoxTrayError("Shared Clipboard: Failed to lock memory (%Rrc)\n", RTErrConvertFromWin32(GetLastError()));
    576577                        GlobalFree(hMem);
    577578                    }
    578579                    else
    579                         LogRel(("Shared Clipboard: No memory for allocating host data buffer\n"));
     580                        VBoxTrayError("Shared Clipboard: No memory for allocating host data buffer\n");
    580581                }
    581582            }
     
    605606            const SHCLFORMATS fFormats = pEvent->u.fReportedFormats;
    606607
    607 #ifdef LOG_ENABLED
    608608            char *pszFmts = ShClFormatsToStrA(fFormats);
    609609            AssertPtrReturn(pszFmts, 0);
    610             LogRel(("Shared Clipboard: Host reported formats '%s'\n", pszFmts));
     610            VBoxTrayVerbose(1, "Shared Clipboard: Host reported formats '%s'\n", pszFmts);
    611611            RTStrFree(pszFmts);
    612 #endif
     612
    613613            if (fFormats != VBOX_SHCL_FMT_NONE) /* Could arrive with some older GA versions. */
    614614            {
     
    647647
    648648            LogFlowFunc(("SHCL_WIN_WM_READ_DATA: fFormat=%#x\n", fFormat));
    649 #ifdef LOG_ENABLED
     649
    650650            char *pszFmts = ShClFormatsToStrA(fFormat);
    651651            AssertPtrReturn(pszFmts, 0);
    652             LogRel(("Shared Clipboard: Sending data to host as '%s'\n", pszFmts));
     652            VBoxTrayVerbose(1, "Shared Clipboard: Sending data to host as '%s'\n", pszFmts);
    653653            RTStrFree(pszFmts);
    654 #endif
     654
    655655            int rc = ShClWinOpen(hwnd);
    656656            HANDLE hClip = NULL;
     
    838838    if (FAILED(hr))
    839839    {
    840         LogRel(("Shared Clipboard: Initializing OLE in window thread failed (%Rhrc) -- file transfers unavailable\n", hr));
     840        VBoxTrayError("Shared Clipboard: Initializing OLE in window thread failed (%Rhrc) -- file transfers unavailable\n", hr);
    841841        /* Not critical, the rest of the clipboard might work. */
    842842    }
    843843    else
    844         LogRel(("Shared Clipboard: Initialized OLE in window thread\n"));
     844        VBoxTrayInfo("Shared Clipboard: Initialized OLE in window thread\n");
    845845#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
    846846
     
    848848    if (RT_FAILURE(rc))
    849849    {
    850         LogRel(("Shared Clipboard: Unable to create window, rc=%Rrc\n", rc));
     850        VBoxTrayError("Shared Clipboard: Unable to create window, rc=%Rrc\n", rc);
    851851        return rc;
    852852    }
     
    857857    bool fSignalled = RT_SUCCESS(rc2);
    858858
    859     LogRel2(("Shared Clipboard: Window thread running\n"));
     859    VBoxTrayInfo("Shared Clipboard: Window thread running\n");
    860860
    861861    if (RT_SUCCESS(rc))
     
    890890#endif
    891891
    892     LogRel(("Shared Clipboard: Window thread ended\n"));
     892    VBoxTrayInfo("Shared Clipboard: Window thread ended\n");
    893893
    894894    LogFlowFuncLeaveRC(rc);
     
    905905}
    906906
    907 DECLCALLBACK(int) vbtrShClInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     907/**
     908 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     909 */
     910static DECLCALLBACK(int) vbtrShClPreInit(void)
     911{
     912    return VINF_SUCCESS;
     913}
     914
     915/**
     916 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     917 */
     918static DECLCALLBACK(int) vbtrShClOption(const char **ppszShort, int argc, char **argv, int *pi)
     919{
     920    RT_NOREF(ppszShort, argc, argv, pi);
     921
     922    return -1;
     923}
     924
     925/**
     926 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     927 */
     928DECLCALLBACK(int) vbtrShClInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    908929{
    909930    LogFlowFuncEnter();
     
    921942    {
    922943        /* Do not use clipboard for remote sessions. */
    923         LogRel(("Shared Clipboard: Clipboard has been disabled for a remote session\n"));
     944        VBoxTrayInfo("Shared Clipboard: Clipboard has been disabled for a remote session\n");
    924945        return VERR_NOT_SUPPORTED;
    925946    }
     
    966987
    967988    if (RT_FAILURE(rc))
    968         LogRel(("Shared Clipboard: Unable to initialize, rc=%Rrc\n", rc));
     989        VBoxTrayError("Shared Clipboard: Unable to initialize, rc=%Rrc\n", rc);
    969990
    970991    LogFlowFuncLeaveRC(rc);
     
    972993}
    973994
     995/**
     996 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
     997 */
    974998DECLCALLBACK(int) vbtrShClWorker(void *pInstance, bool volatile *pfShutdown)
    975999{
     
    9881012    const PSHCLWINCTX pWinCtx = &pCtx->Win;
    9891013
    990     LogRel2(("Shared Clipboard: Worker loop running\n"));
     1014    VBoxTrayVerbose(1, "Shared Clipboard: Worker loop running\n");
    9911015
    9921016#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     
    9941018    if (FAILED(hr))
    9951019    {
    996         LogRel(("Shared Clipboard: Initializing OLE in worker thread failed (%Rhrc) -- file transfers unavailable\n", hr));
     1020        VBoxTrayError("Shared Clipboard: Initializing OLE in worker thread failed (%Rhrc) -- file transfers unavailable\n", hr);
    9971021        /* Not critical, the rest of the clipboard might work. */
    9981022    }
    9991023    else
    1000         LogRel(("Shared Clipboard: Initialized OLE in worker thread\n"));
     1024        VBoxTrayInfo("Shared Clipboard: Initialized OLE in worker thread\n");
    10011025
    10021026    /*
     
    10931117                case VBGLR3CLIPBOARDEVENTTYPE_QUIT:
    10941118                {
    1095                     LogRel2(("Shared Clipboard: Host requested termination\n"));
     1119                    VBoxTrayVerbose(1, "Shared Clipboard: Host requested termination\n");
    10961120                    ASMAtomicXchgBool(pfShutdown, true);
    10971121                    break;
     
    11301154    }
    11311155
    1132     LogRel2(("Shared Clipboard: Worker loop ended\n"));
     1156    VBoxTrayVerbose(1, "Shared Clipboard: Worker loop ended\n");
    11331157
    11341158#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     
    11411165}
    11421166
     1167/**
     1168 * @interface_method_impl{VBOXSERVICEDESC,pfnStop}
     1169 */
    11431170DECLCALLBACK(int) vbtrShClStop(void *pInstance)
    11441171{
     
    11651192}
    11661193
     1194/**
     1195 * @interface_method_impl{VBOXSERVICEDESC,pfnDestroy}
     1196 */
    11671197DECLCALLBACK(void) vbtrShClDestroy(void *pInstance)
    11681198{
     
    11771207    LogFlowFunc(("pCtx=%p\n", pCtx));
    11781208
    1179     LogRel2(("Shared Clipboard: Destroying ...\n"));
     1209    VBoxTrayVerbose(1, "Shared Clipboard: Destroying ...\n");
    11801210
    11811211    const PSHCLWINCTX pWinCtx = &pCtx->Win;
     
    12061236    RTReqQueueDestroy(pCtx->Win.hReqQ);
    12071237
    1208     LogRel2(("Shared Clipboard: Destroyed\n"));
     1238    VBoxTrayVerbose(1, "Shared Clipboard: Destroyed\n");
    12091239
    12101240    return;
     
    12141244 * The service description.
    12151245 */
    1216 VBOXSERVICEDESC g_SvcDescClipboard =
     1246VBOXTRAYSVCDESC g_SvcDescClipboard =
    12171247{
    12181248    /* pszName. */
     
    12201250    /* pszDescription. */
    12211251    "Shared Clipboard",
     1252    /* pszUsage. */
     1253    NULL,
     1254    /* pszOptions. */
     1255    NULL,
    12221256    /* methods */
     1257    vbtrShClPreInit,
     1258    vbtrShClOption,
    12231259    vbtrShClInit,
    12241260    vbtrShClWorker,
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDesktopTracking.cpp

    r106061 r106411  
    216216    gVBoxDt.fIsInputDesktop = TRUE;
    217217
     218    if (RT_FAILURE(rc))
     219        VBoxTrayError("Initializing desktop tracking failed with %Rrc\n", rc);
     220
    218221    return rc;
    219222}
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp

    r106061 r106411  
    5151typedef struct _VBOXDISPLAYCONTEXT
    5252{
    53     const VBOXSERVICEENV *pEnv;
     53    const VBOXTRAYSVCENV *pEnv;
    5454    BOOL fAnyX;
    5555    /** ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
     
    8383
    8484
    85 static DECLCALLBACK(int) VBoxDisplayInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     85/**
     86 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     87 */
     88static DECLCALLBACK(int) vbtrDispPreInit(void)
     89{
     90    return VINF_SUCCESS;
     91}
     92
     93/**
     94 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     95 */
     96static DECLCALLBACK(int) vbtrDispOption(const char **ppszShort, int argc, char **argv, int *pi)
     97{
     98    RT_NOREF(ppszShort, argc, argv, pi);
     99
     100    return -1;
     101}
     102
     103/**
     104 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     105 */
     106static DECLCALLBACK(int) vbtrDisplayInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    86107{
    87108    LogFlowFuncEnter();
     
    172193}
    173194
    174 static DECLCALLBACK(void) VBoxDisplayDestroy(void *pInstance)
     195/**
     196 * @interface_method_impl{VBOXSERVICEDESC,pfnDestroy}
     197 */
     198static DECLCALLBACK(void) vbtrDisplayDestroy(void *pInstance)
    175199{
    176200    RT_NOREF(pInstance);
     
    898922
    899923/**
    900  * Thread function to wait for and process display change requests.
     924 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
    901925 */
    902 static DECLCALLBACK(int) VBoxDisplayWorker(void *pvInstance, bool volatile *pfShutdown)
     926static DECLCALLBACK(int) vbtrDisplayWorker(void *pvInstance, bool volatile *pfShutdown)
    903927{
    904928    AssertPtr(pvInstance);
     
    9891013 * The service description.
    9901014 */
    991 VBOXSERVICEDESC g_SvcDescDisplay =
     1015VBOXTRAYSVCDESC g_SvcDescDisplay =
    9921016{
    9931017    /* pszName. */
     
    9951019    /* pszDescription. */
    9961020    "Display Notifications",
     1021    /* pszUsage. */
     1022    NULL,
     1023    /* pszOptions. */
     1024    NULL,
    9971025    /* methods */
    998     VBoxDisplayInit,
    999     VBoxDisplayWorker,
     1026    vbtrDispPreInit,
     1027    vbtrDispOption,
     1028    vbtrDisplayInit,
     1029    vbtrDisplayWorker,
    10001030    NULL /* pfnStop */,
    1001     VBoxDisplayDestroy
     1031    vbtrDisplayDestroy
    10021032};
    10031033
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnD.cpp

    r106061 r106411  
    3535#include <iprt/win/windows.h>
    3636#include "VBoxTray.h"
     37#include "VBoxTrayInternal.h"
    3738#include "VBoxHelpers.h"
    3839#include "VBoxDnD.h"
     
    130131 * Initializes the proxy window with a given DnD context.
    131132 *
    132  * @return  IPRT status code.
     133 * @return  VBox status code.
    133134 * @param   a_pCtx  Pointer to context to use.
    134135 */
     
    161162
    162163    if (RT_FAILURE(rc))
    163         LogRel(("DnD: Failed to initialize proxy window, rc=%Rrc\n", rc));
     164        VBoxTrayError("DnD: Failed to initialize proxy window, rc=%Rrc\n", rc);
    164165
    165166    LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
     
    203204 * Thread for handling the window's message pump.
    204205 *
    205  * @return  IPRT status code.
     206 * @return  VBox status code.
    206207 * @param   hThread                 Handle to this thread.
    207208 * @param   pvUser                  Pointer to VBoxDnDWnd instance which
     
    312313    else
    313314    {
    314         LogRel(("DnD: Unable to initialize OLE, hr=%Rhrc\n", hr));
     315        VBoxTrayError("DnD: Unable to initialize OLE, hr=%Rhrc\n", hr);
    315316        rc = VERR_COM_UNEXPECTED;
    316317    }
     
    415416            if (RT_FAILURE(rc))
    416417            {
    417                 LogRel(("DnD: Failed to create proxy window, rc=%Rrc\n", rc));
     418                VBoxTrayError("DnD: Failed to create proxy window, rc=%Rrc\n", rc);
    418419                return -1;
    419420            }
     
    626627                case VBGLR3DNDEVENTTYPE_QUIT:
    627628                {
    628                     LogRel(("DnD: Received quit message, shutting down ...\n"));
     629                    VBoxTrayInfo("DnD: Received quit message, shutting down ...\n");
    629630                    PostQuitMessage(0);
    630631                }
     
    652653                default:
    653654                {
    654                     LogRel(("DnD: Received unsupported message '%RU32'\n", pVbglR3Event->enmType));
     655                    VBoxTrayVerbose(1, "DnD: Received unsupported message '%RU32'\n", pVbglR3Event->enmType);
    655656                    rc = VERR_NOT_SUPPORTED;
    656657                    break;
     
    662663            {
    663664                /* Tell the user. */
    664                 LogRel(("DnD: Processing message %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc));
     665                VBoxTrayError("DnD: Processing message %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc);
    665666
    666667                /* If anything went wrong, do a reset and start over. */
     
    691692 * Registers this proxy window as a local drop target.
    692693 *
    693  * @return  IPRT status code.
     694 * @return  VBox status code.
    694695 */
    695696int VBoxDnDWnd::RegisterAsDropTarget(void)
     
    721722    }
    722723    if (hrc != DRAGDROP_E_INVALIDHWND) /* Could be because the DnD host service is not available. */
    723         LogRel(("DnD: Creating drop target failed with hr=%Rhrc\n", hrc));
     724        VBoxTrayError("DnD: Creating drop target failed with hr=%Rhrc\n", hrc);
     725
    724726    LogFlowFuncLeaveRC(VERR_NOT_SUPPORTED);
    725727    return VERR_NOT_SUPPORTED; /* Report back DnD as not being supported. */
     
    729731 * Unregisters this proxy as a drop target.
    730732 *
    731  * @return  IPRT status code.
     733 * @return  VBox status code.
    732734 */
    733735int VBoxDnDWnd::UnregisterAsDropTarget(void)
     
    761763 * Handles the creation of a proxy window.
    762764 *
    763  * @return  IPRT status code.
     765 * @return  VBox status code.
    764766 */
    765767int VBoxDnDWnd::OnCreate(void)
     
    769771    if (RT_FAILURE(rc))
    770772    {
    771         LogRel(("DnD: Connection to host service failed, rc=%Rrc\n", rc));
     773        VBoxTrayError("DnD: Connection to host service failed, rc=%Rrc\n", rc);
    772774        return rc;
    773775    }
     
    796798{
    797799    LogFlowThisFunc(("mMode=%ld, mState=%RU32\n", m_enmMode, m_enmState));
    798     LogRel(("DnD: Drag and drop operation aborted\n"));
     800    VBoxTrayInfo("DnD: Drag and drop operation aborted\n");
    799801
    800802    int rc = RTCritSectEnter(&m_CritSect);
     
    820822 * the guest's screen to initiate a host -> guest DnD operation.
    821823 *
    822  * @return  IPRT status code.
     824 * @return  VBox status code.
    823825 * @param   a_lstFormats            Supported formats offered by the host.
    824826 * @param   a_fDndLstActionsAllowed Supported actions offered by the host.
     
    859861    AssertReturnStmt(paFormatEtc, RTMemTmpFree(paFormatEtc), VERR_NO_TMP_MEMORY);
    860862
    861     LogRel2(("DnD: Reported formats:\n"));
     863    VBoxTrayVerbose(1, "DnD: Reported formats:\n");
    862864    for (size_t i = 0; i < a_lstFormats.size(); i++)
    863865    {
     
    908910        }
    909911
    910         LogRel2(("DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported));
     912        VBoxTrayVerbose(1, "DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported);
    911913    }
    912914
     
    927929        }
    928930
    929         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    930                           strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
    931                           15 * 1000 /* Time to display in msec */, NIIF_INFO);
     931        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     932                                    strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
     933                                    15 * 1000 /* Time to display in msec */, NIIF_INFO);
    932934    }
    933935
     
    938940    if (cFormatsActive)
    939941    {
    940         LogRel2(("DnD: %RU32 supported formats found:\n", cFormatsActive));
     942        VBoxTrayVerbose(1, "DnD: %RU32 supported formats found:\n", cFormatsActive);
    941943        for (size_t i = 0; i < cFormatsActive; i++)
    942             LogRel2(("DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str()));
     944            VBoxTrayVerbose(1, "DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str());
    943945    }
    944946    else
    945         LogRel(("DnD: Warning: No supported drag and drop formats on the guest found!\n"));
     947        VBoxTrayInfo("DnD: Warning: No supported drag and drop formats on the guest found!\n");
    946948
    947949    /*
     
    961963    }
    962964
    963     LogRel2(("DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects));
     965    VBoxTrayVerbose(1, "DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects);
    964966
    965967#ifdef RT_EXCEPTIONS_ENABLED
     
    994996 * the guest's screen.
    995997 *
    996  * @return  IPRT status code.
     998 * @return  VBox status code.
    997999 * @param   u32xPos                 Absolute X position (in pixels) of the host cursor
    9981000 *                                  inside the guest.
     
    10441046 * the guest's screen again.
    10451047 *
    1046  * @return  IPRT status code.
     1048 * @return  VBox status code.
    10471049 */
    10481050int VBoxDnDWnd::OnHgLeave(void)
     
    10521054
    10531055    if (g_cVerbosity)
    1054         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1055                           "Leave: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
    1056                           15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1056        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1057                                    "Leave: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
     1058                                    15 * 1000 /* Time to display in msec */, NIIF_INFO);
    10571059
    10581060    int rc = Abort();
     
    10661068 * and therefore start a "drop" action in the guest.
    10671069 *
    1068  * @return  IPRT status code.
     1070 * @return  VBox status code.
    10691071 */
    10701072int VBoxDnDWnd::OnHgDrop(void)
     
    10791081    {
    10801082        if (g_cVerbosity)
    1081             hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1082                               "Drop: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
    1083                               15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1083            VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1084                                        "Drop: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
     1085                                        15 * 1000 /* Time to display in msec */, NIIF_INFO);
    10841086
    10851087        if (m_lstFmtActive.size() >= 1)
     
    11011103            if (RT_SUCCESS(rc))
    11021104            {
    1103                 LogRel(("DnD: Requesting data as '%s' ...\n", m_strFmtReq.c_str()));
     1105                VBoxTrayInfo("DnD: Requesting data as '%s' ...\n", m_strFmtReq.c_str());
    11041106                rc = VbglR3DnDHGSendReqData(&m_cmdCtx, m_strFmtReq.c_str());
    11051107                if (RT_FAILURE(rc))
     
    11091111        }
    11101112        else /* Should never happen. */
    1111             LogRel(("DnD: Error: Host did not specify a data format for drop data\n"));
     1113            VBoxTrayError("DnD: Host did not specify a data format for drop data\n");
    11121114    }
    11131115
     
    11201122 * to the guest after a "drop" event.
    11211123 *
    1122  * @return  IPRT status code.
     1124 * @return  VBox status code.
    11231125 * @param   pMeta                   Pointer to meta data received.
    11241126 */
     
    11471149                case VBGLR3GUESTDNDMETADATATYPE_URI_LIST:
    11481150                {
    1149                     LogRel2(("DnD: URI transfer root directory is '%s'\n", DnDTransferListGetRootPathAbs(&pMeta->u.URI.Transfer)));
     1151                    VBoxTrayVerbose(1, "DnD: URI transfer root directory is '%s'\n",
     1152                                    DnDTransferListGetRootPathAbs(&pMeta->u.URI.Transfer));
    11501153
    11511154                    char  *pszBuf;
     
    11861189 * host -> guest operation.
    11871190 *
    1188  * @return  IPRT status code.
     1191 * @return  VBox status code.
    11891192 */
    11901193int VBoxDnDWnd::OnHgCancel(void)
     
    12131216 * this class again.
    12141217 *
    1215  * @return  IPRT status code.
     1218 * @return  VBox status code.
    12161219 */
    12171220int VBoxDnDWnd::OnGhIsDnDPending(void)
     
    13351338                case VERR_ACCESS_DENIED:
    13361339                {
    1337                     rc = hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1338                                            szMsg, szTitle,
    1339                                            15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1340                    rc = VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1341                                                     szMsg, szTitle,
     1342                                                     15 * 1000 /* Time to display in msec */, NIIF_INFO);
    13401343                    AssertRC(rc);
    13411344                    break;
     
    13461349            }
    13471350
    1348             LogRel2(("DnD: Host refuses drag and drop operation from guest: %Rrc\n", rc2));
     1351            VBoxTrayVerbose(1, "DnD: Host refuses drag and drop operation from guest: %Rrc\n", rc2);
    13491352            Reset();
    13501353        }
     
    13631366 * to send data in a specific format the host requested.
    13641367 *
    1365  * @return  IPRT status code.
     1368 * @return  VBox status code.
    13661369 * @param   pszFormat               Format the host requests the data in.
    13671370 * @param   cbFormat                Size (in bytes) of format string.
     
    13811384            strMsg += RTCStringFmt("Format: %s\n", strFormat.c_str());
    13821385
    1383             hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1384                               strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
    1385                               15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1386            VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1387                                        strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
     1388                                        15 * 1000 /* Time to display in msec */, NIIF_INFO);
    13861389        }
    13871390
     
    14481451 * this class after processing.
    14491452 *
    1450  * @return  IPRT status code.
     1453 * @return  VBox status code.
    14511454 * @param   pEvent                  Event to inject.
    14521455 */
     
    14641467        if (s_iBitchedAboutFailedDnDMessages++ < 32)
    14651468        {
    1466             LogRel(("DnD: Processing event %p failed with %ld (%Rrc), skipping\n",
    1467                     pEvent, dwErr, RTErrConvertFromWin32(dwErr)));
     1469            VBoxTrayError("DnD: Processing event %p failed with %ld (%Rrc), skipping\n",
     1470                          pEvent, dwErr, RTErrConvertFromWin32(dwErr));
    14681471        }
    14691472
     
    14831486 * and do a reconnect to the DnD HGCM service.
    14841487 *
    1485  * @returns IPRT status code.
     1488 * @returns VBox status code.
    14861489 */
    14871490int VBoxDnDWnd::checkForSessionChange(void)
     
    15081511 * Hides the proxy window again.
    15091512 *
    1510  * @return  IPRT status code.
     1513 * @return  VBox status code.
    15111514 */
    15121515int VBoxDnDWnd::Hide(void)
     
    15241527 * spawned across all active guest monitors.
    15251528 *
    1526  * @return  IPRT status code.
     1529 * @return  VBox status code.
    15271530 */
    15281531int VBoxDnDWnd::makeFullscreen(void)
     
    15881591        {
    15891592            DWORD dwErr = GetLastError();
    1590             LogRel(("DnD: Failed to set proxy window position, rc=%Rrc\n",
    1591                     RTErrConvertFromWin32(dwErr)));
     1593            VBoxTrayError("DnD: Failed to set proxy window position, rc=%Rrc\n",
     1594                          RTErrConvertFromWin32(dwErr));
    15921595        }
    15931596    }
    15941597    else
    1595         LogRel(("DnD: Failed to determine virtual screen size, rc=%Rrc\n", rc));
     1598        VBoxTrayError("DnD: Failed to determine virtual screen size, rc=%Rrc\n", rc);
    15961599
    15971600    LogFlowFuncLeaveRC(rc);
     
    16021605 * Moves the guest mouse cursor to a specific position.
    16031606 *
    1604  * @return  IPRT status code.
     1607 * @return  VBox status code.
    16051608 * @param   x                       X position (in pixels) to move cursor to.
    16061609 * @param   y                       Y position (in pixels) to move cursor to.
     
    16481651 * Releases a previously pressed left guest mouse button.
    16491652 *
    1650  * @return  IPRT status code.
     1653 * @return  VBox status code.
    16511654 */
    16521655int VBoxDnDWnd::mouseRelease(void)
     
    16991702 * Sets the current operation mode of this proxy window.
    17001703 *
    1701  * @return  IPRT status code.
     1704 * @return  VBox status code.
    17021705 * @param   enmMode                 New mode to set.
    17031706 */
     
    17511754}
    17521755
    1753 /**
    1754  * Initializes drag and drop.
    1755  *
    1756  * @return  IPRT status code.
    1757  * @param   pEnv                        The DnD service's environment.
    1758  * @param   ppInstance                  The instance pointer which refer to this object.
    1759  */
    1760 DECLCALLBACK(int) VBoxDnDInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     1756
     1757/**
     1758 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     1759 */
     1760static DECLCALLBACK(int) vbtrDnDPreInit(void)
     1761{
     1762    return VINF_SUCCESS;
     1763}
     1764
     1765
     1766/**
     1767 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     1768 */
     1769static DECLCALLBACK(int) vbtrDnDOption(const char **ppszShort, int argc, char **argv, int *pi)
     1770{
     1771    RT_NOREF(ppszShort, argc, argv, pi);
     1772
     1773    return -1;
     1774}
     1775
     1776/**
     1777 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     1778 */
     1779DECLCALLBACK(int) vbtrDnDInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    17611780{
    17621781    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
     
    17741793    {
    17751794        /* Do not do drag and drop for remote sessions. */
    1776         LogRel(("DnD: Drag and drop has been disabled for a remote session\n"));
     1795        VBoxTrayInfo("DnD: Drag and drop has been disabled for a remote session\n");
    17771796        rc = VERR_NOT_SUPPORTED;
    17781797    }
     
    17911810        if (!fSupportedOS)
    17921811        {
    1793             LogRel(("DnD: Not supported Windows version, disabling drag and drop support\n"));
     1812            VBoxTrayInfo("DnD: Not supported Windows version, disabling drag and drop support\n");
    17941813            rc = VERR_NOT_SUPPORTED;
    17951814        }
     
    18421861        *ppInstance = pCtx;
    18431862
    1844         LogRel(("DnD: Drag and drop service successfully started\n"));
     1863        VBoxTrayInfo("DnD: Drag and drop service successfully started\n");
    18451864    }
    18461865    else
    1847         LogRel(("DnD: Initializing drag and drop service failed with rc=%Rrc\n", rc));
     1866        VBoxTrayError("DnD: Initializing drag and drop service failed with rc=%Rrc\n", rc);
    18481867
    18491868    LogFlowFuncLeaveRC(rc);
     
    18511870}
    18521871
    1853 DECLCALLBACK(int) VBoxDnDStop(void *pInstance)
     1872/**
     1873 * @interface_method_impl{VBOXSERVICEDESC,pfnStop}
     1874 */
     1875DECLCALLBACK(int) vbtrDnDStop(void *pInstance)
    18541876{
    18551877    AssertPtrReturn(pInstance, VERR_INVALID_POINTER);
     
    18701892}
    18711893
    1872 DECLCALLBACK(void) VBoxDnDDestroy(void *pInstance)
     1894/**
     1895 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     1896 */
     1897DECLCALLBACK(void) vbtrDnDDestroy(void *pInstance)
    18731898{
    18741899    AssertPtrReturnVoid(pInstance);
     
    18971922}
    18981923
    1899 DECLCALLBACK(int) VBoxDnDWorker(void *pInstance, bool volatile *pfShutdown)
     1924/**
     1925 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
     1926 */
     1927DECLCALLBACK(int) vbtrDnDWorker(void *pInstance, bool volatile *pfShutdown)
    19001928{
    19011929    AssertPtr(pInstance);
     
    19181946
    19191947    if (g_cVerbosity)
    1920         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1921                           RTCStringFmt("Running (worker client ID %RU32)", pCtx->cmdCtx.uClientID).c_str(),
    1922                           VBOX_DND_SHOWBALLOON_HEADER,
    1923                           15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1948        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1949                                    RTCStringFmt("Running (worker client ID %RU32)", pCtx->cmdCtx.uClientID).c_str(),
     1950                                    VBOX_DND_SHOWBALLOON_HEADER,
     1951                                    15 * 1000 /* Time to display in msec */, NIIF_INFO);
    19241952
    19251953    /** @todo At the moment we only have one DnD proxy window. */
     
    19501978            cMsgSkippedInvalid = 0; /* Reset skipped messages count. */
    19511979
    1952             LogRel2(("DnD: Received new event, type=%RU32, rc=%Rrc\n", pVbglR3Event->enmType, rc));
     1980            VBoxTrayVerbose(2, "DnD: Received new event, type=%RU32, rc=%Rrc\n", pVbglR3Event->enmType, rc);
    19531981
    19541982            /* pEvent now owns pVbglR3Event. */
     
    19631991            }
    19641992            else
    1965                 LogRel(("DnD: Processing proxy window event %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc));
     1993                VBoxTrayInfo("DnD: Processing proxy window event %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc);
    19661994        }
    19671995
     
    19812009            if (cMsgSkippedInvalid++ > 32)
    19822010            {
    1983                 LogRel(("DnD: Too many invalid/skipped messages from host, exiting ...\n"));
     2011                VBoxTrayInfo("DnD: Too many invalid/skipped messages from host, exiting ...\n");
    19842012                break;
    19852013            }
     
    20112039    VbglR3DnDDisconnect(&pCtx->cmdCtx);
    20122040
    2013     LogRel(("DnD: Ended\n"));
     2041    VBoxTrayInfo("DnD: Ended\n");
    20142042
    20152043    LogFlowFuncLeaveRC(rc);
     
    20202048 * The service description.
    20212049 */
    2022 VBOXSERVICEDESC g_SvcDescDnD =
     2050VBOXTRAYSVCDESC g_SvcDescDnD =
    20232051{
    20242052    /* pszName. */
     
    20262054    /* pszDescription. */
    20272055    "Drag and Drop",
     2056    /* pszUsage. */
     2057    NULL,
     2058    /* pszOptions. */
     2059    NULL,
    20282060    /* methods */
    2029     VBoxDnDInit,
    2030     VBoxDnDWorker,
    2031     VBoxDnDStop,
    2032     VBoxDnDDestroy
     2061    vbtrDnDPreInit,
     2062    vbtrDnDOption,
     2063    vbtrDnDInit,
     2064    vbtrDnDWorker,
     2065    vbtrDnDStop,
     2066    vbtrDnDDestroy
    20332067};
    20342068
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnD.h

    r106061 r106411  
    276276{
    277277    /** Pointer to the service environment. */
    278     const VBOXSERVICEENV      *pEnv;
     278    const VBOXTRAYSVCENV      *pEnv;
    279279    /** Started indicator. */
    280280    bool                       fStarted;
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDDataObject.cpp

    r106061 r106411  
    4040
    4141#include "VBoxTray.h"
     42#include "VBoxTrayInternal.h"
    4243#include "VBoxHelpers.h"
    4344#include "VBoxDnD.h"
     
    129130    if (m_enmStatus == Status_Dropping)
    130131    {
    131         LogRel2(("DnD: Waiting for drop event ...\n"));
     132        VBoxTrayVerbose(2, "DnD: Waiting for drop event ...\n");
    132133        int rc2 = RTSemEventWait(m_EvtDropped, RT_INDEFINITE_WAIT);
    133134        LogFlowFunc(("rc2=%Rrc, mStatus=%ld\n", rc2, m_enmStatus)); RT_NOREF(rc2);
     
    136137    if (m_enmStatus == Status_Dropped)
    137138    {
    138         LogRel2(("DnD: Drop event received\n"));
    139         LogRel3(("DnD: cfFormat=%RI16, sFormat=%s, tyMed=%RU32, dwAspect=%RU32\n",
    140                  pThisFormat->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat),
    141                  pThisFormat->tymed, pThisFormat->dwAspect));
    142         LogRel3(("DnD: Got strFormat=%s, pvData=%p, cbData=%RU32\n",
    143                   m_strFormat.c_str(), m_pvData, m_cbData));
     139        VBoxTrayVerbose(2, "DnD: Drop event received\n");
     140        VBoxTrayVerbose(3, "DnD: cfFormat=%RI16, sFormat=%s, tyMed=%RU32, dwAspect=%RU32\n",
     141                        pThisFormat->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat),
     142                        pThisFormat->tymed, pThisFormat->dwAspect);
     143        VBoxTrayVerbose(3, "DnD: Got strFormat=%s, pvData=%p, cbData=%RU32\n",
     144                        m_strFormat.c_str(), m_pvData, m_cbData);
    144145
    145146        /*
     
    160161                && cFiles)
    161162            {
    162                 LogRel2(("DnD: Files (%zu)\n", cFiles));
     163                VBoxTrayVerbose(1, "DnD: Files (%zu)\n", cFiles);
    163164                for (size_t i = 0; i < cFiles; i++)
    164                     LogRel2(("\tDnD: File '%s'\n", papszFiles[i]));
     165                    VBoxTrayVerbose(1, "\tDnD: File '%s'\n", papszFiles[i]);
    165166
    166167#if 0
     
    636637            && pFormatEtc->dwAspect == m_paFormatEtc[i].dwAspect)
    637638        {
    638             LogRel3(("DnD: Format found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32, ulIndex=%RU32\n",
    639                       pFormatEtc->tymed, pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(m_paFormatEtc[i].cfFormat),
    640                       pFormatEtc->dwAspect, i));
     639            VBoxTrayVerbose(3, "DnD: Format found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32, ulIndex=%RU32\n",
     640                            pFormatEtc->tymed, pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(m_paFormatEtc[i].cfFormat),
     641                            pFormatEtc->dwAspect, i);
    641642            if (puIndex)
    642643                *puIndex = i;
     
    645646    }
    646647
    647     LogRel3(("DnD: Format NOT found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32\n",
    648              pFormatEtc->tymed, pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat),
    649              pFormatEtc->dwAspect));
     648    VBoxTrayVerbose(3, "DnD: Format NOT found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32\n",
     649                    pFormatEtc->tymed, pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat),
     650                    pFormatEtc->dwAspect);
    650651
    651652    return false;
     
    728729
    729730    /* Signal in any case. */
    730     LogRel2(("DnD: Signalling drop event\n"));
     731    VBoxTrayVerbose(2, "DnD: Signalling drop event\n");
    731732
    732733    int rc2 = RTSemEventSignal(m_EvtDropped);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDDropTarget.cpp

    r106061 r106411  
    3434
    3535#include "VBoxTray.h"
     36#include "VBoxTrayInternal.h"
    3637#include "VBoxHelpers.h"
    3738#include "VBoxDnD.h"
     
    120121    if (SUCCEEDED(hr2))
    121122    {
    122         LogRel(("DnD: The following formats were offered to us:\n"));
     123        VBoxTrayVerbose(1, "DnD: The following formats were offered to us:\n");
    123124
    124125        FORMATETC curFormatEtc;
     
    129130            hr2 = GetClipboardFormatNameW(curFormatEtc.cfFormat, wszCfName,
    130131                                          sizeof(wszCfName) / sizeof(WCHAR));
    131             LogRel(("\tcfFormat=%RI16 (%s), tyMed=%RI32, dwAspect=%RI32, strCustomName=%ls, hr=%Rhrc\n",
    132                     curFormatEtc.cfFormat,
    133                     VBoxDnDDataObject::ClipboardFormatToString(curFormatEtc.cfFormat),
    134                     curFormatEtc.tymed,
    135                     curFormatEtc.dwAspect,
    136                     wszCfName, hr2));
     132            VBoxTrayVerbose(1, "\tcfFormat=%RI16 (%s), tyMed=%RI32, dwAspect=%RI32, strCustomName=%ls, hr=%Rhrc\n",
     133                            curFormatEtc.cfFormat,
     134                            VBoxDnDDataObject::ClipboardFormatToString(curFormatEtc.cfFormat),
     135                            curFormatEtc.tymed,
     136                            curFormatEtc.dwAspect,
     137                            wszCfName, hr2);
    137138        }
    138139
     
    228229            case ERROR_INVALID_FUNCTION:
    229230            {
    230                 LogRel(("DnD: Drag and drop format is not supported by VBoxTray\n"));
     231                VBoxTrayError("DnD: Drag and drop format is not supported by VBoxTray\n");
    231232                VBoxDnDDropTarget::DumpFormats(pDataObject);
    232233                break;
     
    353354                        size_t cbSize = GlobalSize(pvData);
    354355
    355                         LogRel(("DnD: Got %zu bytes of %s\n", cbSize,
    356                                                                 m_FormatEtc.cfFormat == CF_TEXT
    357                                                               ? "ANSI text" : "Unicode text"));
     356                        VBoxTrayVerbose(2, "DnD: Got %zu bytes of %s\n", cbSize,
     357                                          m_FormatEtc.cfFormat == CF_TEXT
     358                                        ? "ANSI text" : "Unicode text");
    358359                        if (cbSize)
    359360                        {
     
    409410                        UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, NULL /* lpszFile */, 0 /* cchFile */);
    410411
    411                         LogRel(("DnD: Got %RU16 file(s), fUnicode=%RTbool\n", cFiles, fUnicode));
     412                        VBoxTrayVerbose(1, "DnD: Got %RU16 file(s), fUnicode=%RTbool\n", cFiles, fUnicode);
    412413
    413414                        for (UINT i = 0; i < cFiles; i++)
     
    466467                                LogFlowFunc(("\tFile: %s (cchFile=%RU16)\n", pszFileUtf8, cchFileUtf8));
    467468
    468                                 LogRel(("DnD: Adding guest file '%s'\n", pszFileUtf8));
     469                                VBoxTrayVerbose(1, "DnD: Adding guest file '%s'\n", pszFileUtf8);
    469470
    470471                                if (RT_SUCCESS(rc))
     
    486487
    487488                            if (RT_FAILURE(rc))
    488                                 LogRel(("DnD: Error handling file entry #%u, rc=%Rrc\n", i, rc));
     489                                VBoxTrayError("DnD: Error handling file entry #%u, rc=%Rrc\n", i, rc);
    489490
    490491                            RTStrFree(pszFileUtf8);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp

    r106061 r106411  
    3030#include <iprt/string.h>
    3131#include <iprt/alloca.h>
     32#include <iprt/stream.h>
    3233#include <iprt/system.h>
    3334#include <iprt/utf16.h>
     
    3536#include <VBox/VBoxGuestLib.h>
    3637
     38#include "VBoxTray.h"
     39#include "VBoxTrayInternal.h"
    3740#include "VBoxHelpers.h"
    3841
    3942
    40 int hlpReportStatus(VBoxGuestFacilityStatus statusCurrent)
    41 {
     43
     44static const char *vboxTrayGstFacilityStsToStr(VBoxGuestFacilityStatus faStatus, bool fShort)
     45{
     46    switch (faStatus)
     47    {
     48        case VBoxGuestFacilityStatus_Inactive:
     49            return fShort ? "inactive"    : "not active";
     50        case VBoxGuestFacilityStatus_Paused:
     51            return fShort ? "paused"      : "paused";
     52        case VBoxGuestFacilityStatus_PreInit:
     53            return fShort ? "preinit"     : "pre-initializing";
     54        case VBoxGuestFacilityStatus_Init:
     55            return fShort ? "init"        : "initializing";
     56        case VBoxGuestFacilityStatus_Active:
     57            return fShort ? "active"      : "active/running";
     58        case VBoxGuestFacilityStatus_Terminating:
     59            return fShort ? "terminating" : "terminating";
     60        case VBoxGuestFacilityStatus_Terminated:
     61            return fShort ? "terminated"  : "terminated";
     62        case VBoxGuestFacilityStatus_Failed:
     63            return fShort ? "failed"      : "failed";
     64        case VBoxGuestFacilityStatus_Unknown:
     65        default:
     66            break;
     67    }
     68    return "unknown";
     69}
     70
     71int VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus statusCurrent)
     72{
     73    if (g_cVerbosity)
     74        VBoxTrayHlpShowBalloonTip(vboxTrayGstFacilityStsToStr(statusCurrent, false /* fShort */),
     75                                  "Reporting status to host", RT_MS_5SEC);
     76
    4277    int rc = VbglR3ReportAdditionsStatus(VBoxGuestFacilityType_VBoxTrayClient,
    4378                                         statusCurrent,
    4479                                         0 /* Flags */);
    4580    if (RT_FAILURE(rc))
    46         Log(("VBoxTray: Could not report VBoxTray status \"%ld\", rc=%Rrc\n", statusCurrent, rc));
     81        VBoxTrayError("Could not report VBoxTray status '%s' to host, rc=%Rrc\n",
     82                      vboxTrayGstFacilityStsToStr(statusCurrent, false /* fShort */), rc);
    4783    return rc;
    4884}
     
    279315}
    280316
    281 int hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID,
    282                       const char *pszMsg, const char *pszTitle,
    283                       UINT uTimeout, DWORD dwInfoFlags)
    284 {
     317int VBoxTrayHlpShowBalloonTipEx(HINSTANCE hInst, HWND hWnd, UINT uID,
     318                              const char *pszMsg, const char *pszTitle,
     319                              UINT uTimeout, DWORD dwInfoFlags)
     320{
     321    VBoxTrayVerbose(2, "Showing balloon tip \"%s\": %s\n", pszMsg, pszTitle);
     322
    285323    NOTIFYICONDATA niData;
    286324    ZeroMemory(&niData, sizeof(NOTIFYICONDATA));
     
    299337    niData.dwInfoFlags = dwInfoFlags;
    300338
    301     /* Do we want to have */
    302 
    303339    /* Is the current OS supported (at least WinXP) for displaying
    304340     * our own icon and do we actually *want* to display our own stuff? */
     
    336372    if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
    337373    {
    338         DWORD dwErr = GetLastError();
    339         return RTErrConvertFromWin32(dwErr);
    340     }
     374        VBoxTrayError("Could not show balloon tip (%#x)\n", GetLastError());
     375        return VERR_INVALID_HANDLE;
     376    }
     377
    341378    return VINF_SUCCESS;
     379}
     380
     381int VBoxTrayHlpShowBalloonTip(const char *pszMsg, const char *pszTitle,
     382                              UINT uTimeout)
     383{
     384    return VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     385                                       pszMsg, pszTitle, uTimeout, NIIF_INFO);
    342386}
    343387
     
    351395 * @param   ...                 Arguments for format string.
    352396 */
    353 void hlpShowMessageBox(const char *pszTitle, UINT uStyle, const char *pszFmt, ...)
     397void VBoxTrayShowMsgBox(const char *pszTitle, UINT uStyle, const char *pszFmt, ...)
    354398{
    355399    if (!uStyle)
     
    363407    if (rc >= 0)
    364408    {
    365         PRTUTF16 pwszTitle;
    366         rc = RTStrToUtf16(pszTitle, &pwszTitle);
    367         if (RT_SUCCESS(rc))
    368         {
    369             PRTUTF16 pwszMsg;
    370             rc = RTStrToUtf16(pszMsg, &pwszMsg);
     409        if (g_fHasConsole)
     410        {
     411            RTPrintf("%s", pszMsg);
     412        }
     413        else
     414        {
     415            PRTUTF16 pwszTitle;
     416            rc = RTStrToUtf16(pszTitle, &pwszTitle);
    371417            if (RT_SUCCESS(rc))
    372418            {
    373                 MessageBoxW(GetDesktopWindow(), pwszMsg, pwszTitle, uStyle);
    374                 RTUtf16Free(pwszMsg);
     419                PRTUTF16 pwszMsg;
     420                rc = RTStrToUtf16(pszMsg, &pwszMsg);
     421                if (RT_SUCCESS(rc))
     422                {
     423                    MessageBoxW(GetDesktopWindow(), pwszMsg, pwszTitle, uStyle);
     424                    RTUtf16Free(pwszMsg);
     425                }
     426                else
     427                    MessageBoxA(GetDesktopWindow(), pszMsg, pszTitle, uStyle);
     428                RTUtf16Free(pwszTitle);
    375429            }
    376             else
    377                 MessageBoxA(GetDesktopWindow(), pszMsg, pszTitle, uStyle);
    378             RTUtf16Free(pwszTitle);
    379430        }
    380431    }
     
    384435}
    385436
     437/**
     438 * Logs a verbose message.
     439 *
     440 * @param   pszFormat   The message text.
     441 * @param   va          Format arguments.
     442 */
     443static void vboxTrayLogV(const char *pszFormat, va_list va)
     444{
     445#ifdef DEBUG0
     446    int rc = RTCritSectEnter(&g_csLog);
     447    if (RT_SUCCESS(rc))
     448    {
     449#endif
     450        char *psz = NULL;
     451        RTStrAPrintfV(&psz, pszFormat, va);
     452
     453        AssertPtr(psz);
     454        LogRel(("%s", psz));
     455
     456        RTStrFree(psz);
     457#ifdef DEBUG0
     458        RTCritSectLeave(&g_csLog);
     459    }
     460#endif
     461}
     462
     463/**
     464 * Logs an information message.
     465 *
     466 * @param   pszFormat   The message text.
     467 * @param   ...         Format arguments.
     468 */
     469void VBoxTrayInfo(const char *pszFormat, ...)
     470{
     471    va_list va;
     472    va_start(va, pszFormat);
     473    vboxTrayLogV(pszFormat, va);
     474    va_end(va);
     475}
     476
     477/**
     478 * Logs an error message.
     479 *
     480 * @returns RTEXITCODE_FAILURE.
     481 * @param   pszFormat   The message text.
     482 * @param   ...         Format arguments.
     483 */
     484RTEXITCODE VBoxTrayError(const char *pszFormat, ...)
     485{
     486    va_list args;
     487    va_start(args, pszFormat);
     488    char *psz = NULL;
     489    RTStrAPrintfV(&psz, pszFormat, args);
     490    va_end(args);
     491
     492    AssertPtr(psz);
     493    LogRel(("Error: %s", psz));
     494
     495    RTStrFree(psz);
     496
     497    return RTEXITCODE_FAILURE;
     498}
     499
     500/**
     501 * Logs a verbose message based on the currently
     502 * set global verbosity level.
     503 *
     504 * @param   iLevel      Minimum log level required to display this message.
     505 * @param   pszFormat   The message text.
     506 * @param   ...         Format arguments.
     507 */
     508void VBoxTrayVerbose(unsigned iLevel, const char *pszFormat, ...)
     509{
     510    if (iLevel <= g_cVerbosity)
     511    {
     512        va_list va;
     513        va_start(va, pszFormat);
     514        vboxTrayLogV(pszFormat, va);
     515        va_end(va);
     516    }
     517}
     518
     519/**
     520 * Displays an error message.
     521 *
     522 * @returns RTEXITCODE_FAILURE.
     523 * @param   pszFormat   The message text.
     524 * @param   ...         Format arguments.
     525 */
     526RTEXITCODE VBoxTrayShowError(const char *pszFormat, ...)
     527{
     528    va_list args;
     529    va_start(args, pszFormat);
     530    char *psz = NULL;
     531    RTStrAPrintfV(&psz, pszFormat, args);
     532    va_end(args);
     533
     534    AssertPtr(psz);
     535
     536    VBoxTrayError("%s", psz);
     537    VBoxTrayShowMsgBox(VBOX_VBOXTRAY_TITLE " - Error", MB_OK | MB_ICONERROR, psz);
     538
     539    RTStrFree(psz);
     540
     541    return RTEXITCODE_FAILURE;
     542}
     543
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h

    r106061 r106411  
    3232#endif
    3333
    34 extern int  hlpReportStatus(VBoxGuestFacilityStatus statusCurrent);
    3534extern void hlpReloadCursor(void);
    3635extern void hlpResizeRect(RECTL *paRects, unsigned nRects, unsigned uPrimary, unsigned uResized, int iNewWidth, int iNewHeight, int iNewPosX, int iNewPosY);
    37 extern int  hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags);
    38 extern void hlpShowMessageBox(const char *pszTitle, UINT uStyle, const char *pszFmt, ...);
     36
     37extern int  VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus statusCurrent);
     38extern int  VBoxTrayHlpShowBalloonTip(const char *pszMsg, const char *pszTitle, UINT uTimeout);
     39extern int  VBoxTrayHlpShowBalloonTipEx(HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags);
     40extern void VBoxTrayShowMsgBox(const char *pszTitle, UINT uStyle, const char *pszFmt, ...);
    3941
    4042#endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxHelpers_h */
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp

    r106061 r106411  
    3232#include "VBoxHostVersion.h"
    3333#include "VBoxTray.h"
     34#include "VBoxTrayInternal.h"
    3435#include "VBoxHelpers.h"
    35 
    3636
    3737
     
    6464                            "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
    6565
    66                 rc = hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    67                                        szMsg, szTitle,
    68                                        5000 /* Time to display in msec */, NIIF_INFO);
    69                 if (RT_FAILURE(rc))
    70                     LogFlowFunc(("Guest Additions update found; however: could not show version notifier balloon tooltip, rc=%Rrc\n", rc));
     66                rc = VBoxTrayHlpShowBalloonTip(szMsg, szTitle, RT_MS_5SEC);
     67
     68                VBoxTrayInfo("Guest Additions update found: %s -> %s\n", pszGuestVersion, pszHostVersion);
    7169            }
    7270
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp

    r106061 r106411  
    5959{
    6060    /** Pointer to the service environment. */
    61     const VBOXSERVICEENV      *pEnv;
     61    const VBOXTRAYSVCENV      *pEnv;
    6262    /** Handle for the local IPC server. */
    6363    RTLOCALIPCSERVER           hServer;
     
    170170     * Showing the balloon tooltip is not critical.
    171171     */
    172     int rc2 = hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     172    VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    173173                                pszMsg, pszTitle, Payload.s.cMsTimeout, Payload.s.uType);
    174     LogFlowFunc(("Showing \"%s\" - \"%s\" (type %RU32, %RU32ms), rc=%Rrc\n",
    175                  pszTitle, pszMsg, Payload.s.cMsTimeout, Payload.s.uType, rc2));
    176     RT_NOREF_PV(rc2);
    177174
    178175    return VINF_SUCCESS;
     
    207204
    208205/**
    209  * Initializes the IPC communication.
    210  *
    211  * @return  IPRT status code.
    212  * @param   pEnv                        The IPC service's environment.
    213  * @param   ppInstance                  The instance pointer which refers to this object.
    214  */
    215 DECLCALLBACK(int) VBoxIPCInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     206 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     207 */
     208static DECLCALLBACK(int) vbtrIPCPreInit(void)
     209{
     210    return VINF_SUCCESS;
     211}
     212
     213
     214/**
     215 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     216 */
     217static DECLCALLBACK(int) vbtrIPCOption(const char **ppszShort, int argc, char **argv, int *pi)
     218{
     219    RT_NOREF(ppszShort, argc, argv, pi);
     220
     221    return -1;
     222}
     223
     224/**
     225 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     226 */
     227DECLCALLBACK(int) vbtrIPCInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    216228{
    217229    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
     
    260272}
    261273
     274/**
     275 * @interface_method_impl{VBOXSERVICEDESC,pfnStop}
     276 */
    262277DECLCALLBACK(void) VBoxIPCStop(void *pInstance)
    263278{
     
    298313}
    299314
    300 DECLCALLBACK(void) VBoxIPCDestroy(void *pInstance)
     315/**
     316 * @interface_method_impl{VBOXSERVICEDESC,pfnDestroy}
     317 */
     318DECLCALLBACK(void) vbtrIPCDestroy(void *pInstance)
    301319{
    302320    AssertPtrReturnVoid(pInstance);
     
    552570 * requests
    553571 */
    554 DECLCALLBACK(int) VBoxIPCWorker(void *pInstance, bool volatile *pfShutdown)
     572DECLCALLBACK(int) vbtrIPCWorker(void *pInstance, bool volatile *pfShutdown)
    555573{
    556574    AssertPtr(pInstance);
     
    606624 * The service description.
    607625 */
    608 VBOXSERVICEDESC g_SvcDescIPC =
     626VBOXTRAYSVCDESC g_SvcDescIPC =
    609627{
    610628    /* pszName. */
     
    612630    /* pszDescription. */
    613631    "Inter-Process Communication",
     632    /* pszUsage. */
     633    NULL,
     634    /* pszOptions. */
     635    NULL,
    614636    /* methods */
    615     VBoxIPCInit,
    616     VBoxIPCWorker,
     637    vbtrIPCPreInit,
     638    vbtrIPCOption,
     639    vbtrIPCInit,
     640    vbtrIPCWorker,
    617641    NULL /* pfnStop */,
    618     VBoxIPCDestroy
     642    vbtrIPCDestroy
    619643};
    620644
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.h

    r106061 r106411  
    3434#endif
    3535
    36 int                VBoxIPCInit    (const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread);
    37 unsigned __stdcall VBoxIPCWorker  (void *pInstance);
    38 void               VBoxIPCStop    (const VBOXSERVICEENV *pEnv, void *pInstance);
    39 void               VBoxIPCDestroy (const VBOXSERVICEENV *pEnv, void *pInstance);
     36int                vbtrIPCInit    (const VBOXTRAYSVCENV *pEnv, void **ppInstance, bool *pfStartThread);
     37unsigned __stdcall vbtrIPCWorker  (void *pInstance);
     38void               VBoxIPCStop    (const VBOXTRAYSVCENV *pEnv, void *pInstance);
     39void               vbtrIPCDestroy (const VBOXTRAYSVCENV *pEnv, void *pInstance);
    4040
    4141#endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxIPC_h */
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp

    r106061 r106411  
    7272typedef struct _VBOXLACONTEXT
    7373{
    74     const VBOXSERVICEENV *pEnv;
     74    const VBOXTRAYSVCENV *pEnv;
    7575
    7676    bool fLogEnabled;
     
    12091209}
    12101210
    1211 DECLCALLBACK(int) VBoxLAInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     1211/**
     1212 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     1213 */
     1214static DECLCALLBACK(int) vbtrLAPreInit(void)
     1215{
     1216    return VINF_SUCCESS;
     1217}
     1218
     1219
     1220/**
     1221 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     1222 */
     1223static DECLCALLBACK(int) vbtrLAOption(const char **ppszShort, int argc, char **argv, int *pi)
     1224{
     1225    RT_NOREF(ppszShort, argc, argv, pi);
     1226
     1227    return -1;
     1228}
     1229
     1230/**
     1231 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     1232 */
     1233DECLCALLBACK(int) vbtrLAInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    12121234{
    12131235    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
     
    12621284}
    12631285
    1264 DECLCALLBACK(void) VBoxLADestroy(void *pInstance)
     1286/**
     1287 * @interface_method_impl{VBOXSERVICEDESC,pfnDestroy}
     1288 */
     1289DECLCALLBACK(void) vbtrLADestroy(void *pInstance)
    12651290{
    12661291    AssertPtrReturnVoid(pInstance);
     
    12821307}
    12831308
    1284 /*
    1285  * Thread function to wait for and process property changes
     1309/**
     1310 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
    12861311 */
    1287 DECLCALLBACK(int) VBoxLAWorker(void *pInstance, bool volatile *pfShutdown)
     1312DECLCALLBACK(int) vbtrLAWorker(void *pInstance, bool volatile *pfShutdown)
    12881313{
    12891314    AssertPtr(pInstance);
     
    14261451 * The service description.
    14271452 */
    1428 VBOXSERVICEDESC g_SvcDescLA =
     1453VBOXTRAYSVCDESC g_SvcDescLA =
    14291454{
    14301455    /* pszName. */
     
    14321457    /* pszDescription. */
    14331458    "Location Awareness",
     1459    /* pszUsage. */
     1460    NULL,
     1461    /* pszOptions. */
     1462    NULL,
    14341463    /* methods */
    1435     VBoxLAInit,
    1436     VBoxLAWorker,
     1464    vbtrLAPreInit,
     1465    vbtrLAOption,
     1466    vbtrLAInit,
     1467    vbtrLAWorker,
    14371468    NULL /* pfnStop */,
    1438     VBoxLADestroy
     1469    vbtrLADestroy
    14391470};
    14401471
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp

    r106061 r106411  
    5252typedef struct _VBOXSEAMLESSCONTEXT
    5353{
    54     const VBOXSERVICEENV *pEnv;
     54    const VBOXTRAYSVCENV *pEnv;
    5555
    5656    RTLDRMOD hModHook;
     
    8282
    8383
    84 static DECLCALLBACK(int) VBoxSeamlessInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     84/**
     85 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     86 */
     87static DECLCALLBACK(int) vbtrSeamlessPreInit(void)
     88{
     89    return VINF_SUCCESS;
     90}
     91
     92/**
     93 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     94 */
     95static DECLCALLBACK(int) vbtrSeamlessOption(const char **ppszShort, int argc, char **argv, int *pi)
     96{
     97    RT_NOREF(ppszShort, argc, argv, pi);
     98
     99    return -1;
     100}
     101
     102/**
     103 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     104 */
     105static DECLCALLBACK(int) vbtrSeamlessInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    85106{
    86107    LogFlowFuncEnter();
     
    135156}
    136157
     158/**
     159 * @interface_method_impl{VBOXSERVICEDESC,pfnDestroy}
     160 */
    137161static DECLCALLBACK(void) VBoxSeamlessDestroy(void *pInstance)
    138162{
     
    394418
    395419/**
    396  * Thread function to wait for and process seamless mode change
    397  * requests
    398  */
    399 static DECLCALLBACK(int) VBoxSeamlessWorker(void *pvInstance, bool volatile *pfShutdown)
     420 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
     421 */
     422static DECLCALLBACK(int) vbtrSeamlessWorker(void *pvInstance, bool volatile *pfShutdown)
    400423{
    401424    AssertPtrReturn(pvInstance, VERR_INVALID_POINTER);
     
    519542 * The service description.
    520543 */
    521 VBOXSERVICEDESC g_SvcDescSeamless =
     544VBOXTRAYSVCDESC g_SvcDescSeamless =
    522545{
    523546    /* pszName. */
     
    525548    /* pszDescription. */
    526549    "Seamless Windows",
     550    /* pszUsage. */
     551    NULL,
     552    /* pszOptions. */
     553    NULL,
    527554    /* methods */
    528     VBoxSeamlessInit,
    529     VBoxSeamlessWorker,
     555    vbtrSeamlessPreInit,
     556    vbtrSeamlessOption,
     557    vbtrSeamlessInit,
     558    vbtrSeamlessWorker,
    530559    NULL /* pfnStop */,
    531560    VBoxSeamlessDestroy
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSessionTracking.cpp

    r106061 r106411  
    3737
    3838#include "VBoxTray.h"
     39#include "VBoxTrayInternal.h"
    3940
    4041
     
    125126        else
    126127        {
    127             DWORD dwErr = GetLastError();
    128             LogRel(("WTSRegisterSessionNotification failed, error = %08X\n", dwErr));
     128            DWORD const dwErr = GetLastError();
     129            VBoxTrayInfo("WTSRegisterSessionNotification failed, error = %08X\n", dwErr);
    129130            if (dwErr == RPC_S_INVALID_BINDING)
    130131            {
     
    144145    else
    145146    {
    146         LogRel(("WtsApi32.dll APIs are not available (%Rrc)\n", rc));
     147        VBoxTrayInfo("WtsApi32.dll APIs are not available (%Rrc)\n", rc);
     148
    147149        gVBoxSt.pfnWTSRegisterSessionNotification = NULL;
    148150        gVBoxSt.pfnWTSUnRegisterSessionNotification = NULL;
     
    153155    gVBoxSt.fIsConsole = TRUE;
    154156    gVBoxSt.enmConnectState = WTSActive;
     157
     158    if (RT_FAILURE(rc))
     159        VBoxTrayError("Initializing sessiosn tracking failed with %Rrc\n", rc);
     160
    155161    return rc;
    156162}
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r106246 r106411  
    5353#include <iprt/asm.h>
    5454#include <iprt/buildconfig.h>
     55#include <iprt/file.h>
    5556#include <iprt/getopt.h>
    5657#include <iprt/ldr.h>
     
    5859#include <iprt/path.h>
    5960#include <iprt/process.h>
     61#include <iprt/stream.h>
    6062#include <iprt/system.h>
    6163#include <iprt/time.h>
     
    8082*   Global Variables                                                                                                             *
    8183*********************************************************************************************************************************/
    82 int                   g_cVerbosity             = 0;
     84/** Mutex for checking if VBoxTray already is running. */
     85HANDLE                g_hMutexAppRunning       = NULL;
     86/** Whether VBoxTray is connected to a (parent) console. */
     87bool                  g_fHasConsole            = false;
     88/** The current verbosity level. */
     89unsigned              g_cVerbosity             = 0;
    8390HANDLE                g_hStopSem;
    8491HANDLE                g_hSeamlessWtNotifyEvent = 0;
     
    9097uint32_t              g_fGuestDisplaysChanged = 0;
    9198
    92 static PRTLOGGER      g_pLoggerRelease = NULL;           /**< This is actually the debug logger in DEBUG builds! */
    93 static uint32_t       g_cHistory = 10;                   /**< Enable log rotation, 10 files. */
    94 static uint32_t       g_uHistoryFileTime = RT_SEC_1DAY;  /**< Max 1 day per file. */
    95 static uint64_t       g_uHistoryFileSize = 100 * _1M;    /**< Max 100MB per file. */
    96 
    97 #ifdef DEBUG_andy
    98 static VBOXSERVICEINFO g_aServices[] =
    99 {
    100     { &g_SvcDescClipboard,      NIL_RTTHREAD, NULL, false, false, false, false, true }
    101 };
    102 #else
     99
    103100/**
    104101 * The details of the services that has been compiled in.
    105102 */
    106 static VBOXSERVICEINFO g_aServices[] =
     103static VBOXTRAYSVCINFO g_aServices[] =
    107104{
    108105    { &g_SvcDescDisplay,        NIL_RTTHREAD, NULL, false, false, false, false, true },
     
    118115#endif
    119116};
    120 #endif
    121 
    122 /* The global message table. */
    123 static VBOXGLOBALMESSAGE g_vboxGlobalMessageTable[] =
     117
     118/**
     119 * The global message table.
     120 */
     121static VBOXTRAYGLOBALMSG g_vboxGlobalMessageTable[] =
    124122{
    125123    /* Windows specific stuff. */
     
    131129    /* VBoxTray specific stuff. */
    132130    /** @todo Add new messages here! */
    133 
    134131    {
    135132        NULL
     
    141138 * get (re-)created. Nice to install our tray icon.
    142139 *
    143  * @return  IPRT status code.
     140 * @return  VBox status code.
    144141 * @param   wParam
    145142 * @param   lParam
     
    151148}
    152149
     150/**
     151 * Creates VBoxTray's tray icon.
     152 *
     153 * @returns VBox status code.
     154 */
    153155static int vboxTrayCreateTrayIcon(void)
    154156{
     
    156158    if (hIcon == NULL)
    157159    {
    158         DWORD dwErr = GetLastError();
    159         LogFunc(("Could not load tray icon, error %08X\n", dwErr));
     160        DWORD const dwErr = GetLastError();
     161        VBoxTrayError("Could not load tray icon (%#x)\n", dwErr);
    160162        return RTErrConvertFromWin32(dwErr);
    161163    }
     
    176178    if (!Shell_NotifyIcon(NIM_ADD, &g_NotifyIconData))
    177179    {
    178         DWORD dwErr = GetLastError();
    179         LogFunc(("Could not create tray icon, error=%ld\n", dwErr));
     180        DWORD const dwErr = GetLastError();
     181        VBoxTrayError("Could not create tray icon (%#x)\n", dwErr);
    180182        rc = RTErrConvertFromWin32(dwErr);
    181183        RT_ZERO(g_NotifyIconData);
     
    187189}
    188190
     191/**
     192 * Removes VBoxTray's tray icon.
     193 *
     194 * @returns VBox status code.
     195 */
    189196static void vboxTrayRemoveTrayIcon(void)
    190197{
     
    213220static DECLCALLBACK(int) vboxTrayServiceThread(RTTHREAD ThreadSelf, void *pvUser)
    214221{
    215     PVBOXSERVICEINFO pSvc = (PVBOXSERVICEINFO)pvUser;
     222    PVBOXTRAYSVCINFO pSvc = (PVBOXTRAYSVCINFO)pvUser;
    216223    AssertPtr(pSvc);
    217224
     
    229236    RTThreadUserSignal(ThreadSelf);
    230237
    231     LogFunc(("Worker for '%s' ended with %Rrc\n", pSvc->pDesc->pszName, rc));
     238    VBoxTrayVerbose(1, "Thread for '%s' ended with %Rrc\n", pSvc->pDesc->pszName, rc);
    232239    return rc;
    233240}
    234241
    235 static int vboxTrayServicesStart(PVBOXSERVICEENV pEnv)
     242/**
     243 * Lazily calls the pfnPreInit method on each service.
     244 *
     245 * @returns VBox status code, error message displayed.
     246 */
     247static int vboxTrayServicesLazyPreInit(void)
     248{
     249    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
     250        if (!g_aServices[j].fPreInited)
     251        {
     252            int rc = g_aServices[j].pDesc->pfnPreInit();
     253            if (RT_FAILURE(rc))
     254                return VBoxTrayError("Service '%s' failed pre-init: %Rrc\n", g_aServices[j].pDesc->pszName, rc);
     255            g_aServices[j].fPreInited = true;
     256        }
     257    return VINF_SUCCESS;
     258}
     259
     260/**
     261 * Starts all services.
     262 *
     263 * @returns VBox status code.
     264 * @param   pEnv                Service environment to use.
     265 */
     266static int vboxTrayServicesStart(PVBOXTRAYSVCENV pEnv)
    236267{
    237268    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
    238269
    239     LogRel(("Starting services ...\n"));
     270    VBoxTrayInfo("Starting services ...\n");
    240271
    241272    int rc = VINF_SUCCESS;
    242273
     274    size_t cServicesStarted = 0;
     275
    243276    for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
    244277    {
    245         PVBOXSERVICEINFO pSvc = &g_aServices[i];
    246         LogRel(("Starting service '%s' ...\n", pSvc->pDesc->pszName));
     278        PVBOXTRAYSVCINFO pSvc = &g_aServices[i];
     279
     280        if (!pSvc->fEnabled)
     281        {
     282            VBoxTrayInfo("Skipping starting service '%s' (disabled)\n", pSvc->pDesc->pszName);
     283            continue;
     284        }
     285
     286        VBoxTrayInfo("Starting service '%s' ...\n", pSvc->pDesc->pszName);
    247287
    248288        pSvc->hThread   = NIL_RTTHREAD;
     
    261301            {
    262302                case VERR_NOT_SUPPORTED:
    263                     LogRel(("Service '%s' is not supported on this system\n", pSvc->pDesc->pszName));
     303                    VBoxTrayInfo("Service '%s' is not supported on this system\n", pSvc->pDesc->pszName);
    264304                    rc2 = VINF_SUCCESS; /* Keep going. */
    265305                    break;
    266306
    267307                case VERR_HGCM_SERVICE_NOT_FOUND:
    268                     LogRel(("Service '%s' is not available on the host\n", pSvc->pDesc->pszName));
     308                    VBoxTrayInfo("Service '%s' is not available on the host\n", pSvc->pDesc->pszName);
    269309                    rc2 = VINF_SUCCESS; /* Keep going. */
    270310                    break;
    271311
    272312                default:
    273                     LogRel(("Failed to initialize service '%s', rc=%Rrc\n", pSvc->pDesc->pszName, rc2));
     313                    VBoxTrayError("Failed to initialize service '%s', rc=%Rrc\n", pSvc->pDesc->pszName, rc2);
    274314                    break;
    275315            }
     
    288328                    if (pSvc->fShutdown)
    289329                    {
    290                         LogRel(("Service '%s' failed to start!\n", pSvc->pDesc->pszName));
     330                        VBoxTrayError("Service '%s' failed to start!\n", pSvc->pDesc->pszName);
    291331                        rc = VERR_GENERAL_FAILURE;
    292332                    }
    293333                    else
    294                         LogRel(("Service '%s' started\n", pSvc->pDesc->pszName));
     334                    {
     335                        cServicesStarted++;
     336                        VBoxTrayInfo("Service '%s' started\n", pSvc->pDesc->pszName);
     337                    }
    295338                }
    296339                else
    297340                {
    298                     LogRel(("Failed to start thread for service '%s': %Rrc\n", rc2));
     341                    VBoxTrayInfo("Failed to start thread for service '%s': %Rrc\n", rc2);
    299342                    if (pSvc->pDesc->pfnDestroy)
    300343                        pSvc->pDesc->pfnDestroy(pSvc->pInstance);
     
    307350    }
    308351
    309     if (RT_SUCCESS(rc))
    310         LogRel(("All services started\n"));
    311     else
    312         LogRel(("Services started, but some with errors\n"));
     352    VBoxTrayInfo("%zu/%zu service(s) started\n", cServicesStarted, RT_ELEMENTS(g_aServices));
     353    if (RT_FAILURE(rc))
     354        VBoxTrayInfo("Some service(s) reported errors when starting -- see log above\n");
    313355
    314356    LogFlowFuncLeaveRC(rc);
     
    316358}
    317359
    318 static int vboxTrayServicesStop(VBOXSERVICEENV *pEnv)
     360/**
     361 * Stops all services.
     362 *
     363 * @returns VBox status code.
     364 * @param   pEnv                Service environment to use.
     365 */
     366static int vboxTrayServicesStop(VBOXTRAYSVCENV *pEnv)
    319367{
    320368    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
    321369
    322     LogRel2(("Stopping all services ...\n"));
     370    VBoxTrayVerbose(1, "Stopping all services ...\n");
    323371
    324372    /*
     
    333381    for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
    334382    {
    335         PVBOXSERVICEINFO pSvc = &g_aServices[i];
     383        PVBOXTRAYSVCINFO pSvc = &g_aServices[i];
    336384        if (   pSvc->fStarted
    337385            && pSvc->pDesc->pfnStop)
    338386        {
    339             LogRel2(("Calling stop function for service '%s' ...\n", pSvc->pDesc->pszName));
     387            VBoxTrayVerbose(1, "Calling stop function for service '%s' ...\n", pSvc->pDesc->pszName);
    340388            int rc2 = pSvc->pDesc->pfnStop(pSvc->pInstance);
    341389            if (RT_FAILURE(rc2))
    342                 LogRel(("Failed to stop service '%s': %Rrc\n", pSvc->pDesc->pszName, rc2));
    343         }
    344     }
    345 
    346     LogRel2(("All stop functions for services called\n"));
     390                VBoxTrayError("Failed to stop service '%s': %Rrc\n", pSvc->pDesc->pszName, rc2);
     391        }
     392    }
     393
     394    VBoxTrayVerbose(2, "All stop functions for services called\n");
    347395
    348396    int rc = VINF_SUCCESS;
     
    353401    for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
    354402    {
    355         PVBOXSERVICEINFO pSvc = &g_aServices[i];
     403        PVBOXTRAYSVCINFO pSvc = &g_aServices[i];
    356404        if (!pSvc->fEnabled) /* Only stop services which were started before. */
    357405            continue;
     
    359407        if (pSvc->hThread != NIL_RTTHREAD)
    360408        {
    361             LogRel2(("Waiting for service '%s' to stop ...\n", pSvc->pDesc->pszName));
     409            VBoxTrayVerbose(1, "Waiting for service '%s' to stop ...\n", pSvc->pDesc->pszName);
    362410            int rc2 = VINF_SUCCESS;
    363411            for (int j = 0; j < 30; j++) /* Wait 30 seconds in total */
     
    369417            if (RT_FAILURE(rc2))
    370418            {
    371                 LogRel(("Service '%s' failed to stop (%Rrc)\n", pSvc->pDesc->pszName, rc2));
     419                VBoxTrayError("Service '%s' failed to stop (%Rrc)\n", pSvc->pDesc->pszName, rc2);
    372420                if (RT_SUCCESS(rc))
    373421                    rc = rc2;
     
    378426            && pSvc->pInstance) /* pInstance might be NULL if initialization of a service failed. */
    379427        {
    380             LogRel2(("Terminating service '%s' ...\n", pSvc->pDesc->pszName));
     428            VBoxTrayVerbose(1, "Terminating service '%s' ...\n", pSvc->pDesc->pszName);
    381429            pSvc->pDesc->pfnDestroy(pSvc->pInstance);
    382430        }
     
    384432
    385433    if (RT_SUCCESS(rc))
    386         LogRel(("All services stopped\n"));
     434        VBoxTrayVerbose(1, "All services stopped\n");
    387435
    388436    LogFlowFuncLeaveRC(rc);
     
    390438}
    391439
    392 static int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
     440/**
     441 * Registers all global window messages of a specific table.
     442 *
     443 * @returns VBox status code.
     444 * @param   pTable              Table to register messages for.
     445 */
     446static int vboxTrayRegisterGlobalMessages(PVBOXTRAYGLOBALMSG pTable)
    393447{
    394448    int rc = VINF_SUCCESS;
     
    403457        {
    404458            DWORD dwErr = GetLastError();
    405             Log(("Registering global message \"%s\" failed, error = %08X\n", dwErr));
     459            VBoxTrayError("Registering global message \"%s\" failed, error = %08X\n", pTable->pszName, dwErr);
    406460            rc = RTErrConvertFromWin32(dwErr);
    407461        }
     
    413467}
    414468
    415 static bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
     469/**
     470 * Handler for global (registered) window messages.
     471 *
     472 * @returns \c true if message got handeled, \c false if not.
     473 * @param   pTable              Message table to look message up in.
     474 * @param   uMsg                Message ID to handle.
     475 * @param   wParam              WPARAM of the message.
     476 * @param   lParam              LPARAM of the message.
     477 */
     478static bool vboxTrayHandleGlobalMessages(PVBOXTRAYGLOBALMSG pTable, UINT uMsg,
    416479                                         WPARAM wParam, LPARAM lParam)
    417480{
     
    434497
    435498/**
    436  * Header/footer callback for the release logger.
    437  *
    438  * @param   pLoggerRelease
    439  * @param   enmPhase
    440  * @param   pfnLog
    441  */
    442 static DECLCALLBACK(void) vboxTrayLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
    443 {
    444     /* Some introductory information. */
    445     static RTTIMESPEC s_TimeSpec;
    446     char szTmp[256];
    447     if (enmPhase == RTLOGPHASE_BEGIN)
    448         RTTimeNow(&s_TimeSpec);
    449     RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
    450 
    451     switch (enmPhase)
    452     {
    453         case RTLOGPHASE_BEGIN:
    454         {
    455             pfnLog(pLoggerRelease,
    456                    "VBoxTray %s r%s %s (%s %s) release log\n"
    457                    "Log opened %s\n",
    458                    RTBldCfgVersion(), RTBldCfgRevisionStr(), VBOX_BUILD_TARGET,
    459                    __DATE__, __TIME__, szTmp);
    460 
    461             int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
    462             if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
    463                 pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp);
    464             vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
    465             if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
    466                 pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp);
    467             vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
    468             if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
    469                 pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp);
    470             if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
    471                 pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp);
    472 
    473             /* the package type is interesting for Linux distributions */
    474             char szExecName[RTPATH_MAX];
    475             char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
    476             pfnLog(pLoggerRelease,
    477                    "Executable: %s\n"
    478                    "Process ID: %u\n"
    479                    "Package type: %s"
    480 #ifdef VBOX_OSE
    481                    " (OSE)"
    482 #endif
    483                    "\n",
    484                    pszExecName ? pszExecName : "unknown",
    485                    RTProcSelf(),
    486                    VBOX_PACKAGE_STRING);
    487             break;
    488         }
    489 
    490         case RTLOGPHASE_PREROTATE:
    491             pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp);
    492             break;
    493 
    494         case RTLOGPHASE_POSTROTATE:
    495             pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp);
    496             break;
    497 
    498         case RTLOGPHASE_END:
    499             pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp);
    500             break;
    501 
    502         default:
    503             /* nothing */;
    504     }
    505 }
    506 
    507 /**
    508  * Creates the default release logger outputting to the specified file.
    509  *
    510  * @return  IPRT status code.
    511  * @param   pszLogFile          Path to log file to use. Can be NULL if not needed.
    512  */
    513 static int vboxTrayLogCreate(const char *pszLogFile)
    514 {
    515     /* Create release (or debug) logger (stdout + file). */
    516     static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
    517 #ifdef DEBUG
    518     static const char s_szEnvVarPfx[] = "VBOXTRAY_LOG";
    519     static const char s_szGroupSettings[] = "all.e.l.f";
    520 #else
    521     static const char s_szEnvVarPfx[] = "VBOXTRAY_RELEASE_LOG";
    522     static const char s_szGroupSettings[] = "all";
    523 #endif
    524     RTERRINFOSTATIC ErrInfo;
    525     int rc = RTLogCreateEx(&g_pLoggerRelease, s_szEnvVarPfx,
    526                            RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG | RTLOGFLAGS_USECRLF,
    527                            s_szGroupSettings, RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX,
    528                            0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT,
    529                            vboxTrayLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
    530                            NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/,
    531                            RTErrInfoInitStatic(&ErrInfo), "%s", pszLogFile ? pszLogFile : "");
    532     if (RT_SUCCESS(rc))
    533     {
    534 #ifdef DEBUG
    535         /* Register this logger as the _debug_ logger. */
    536         RTLogSetDefaultInstance(g_pLoggerRelease);
    537 #else
    538         /* Register this logger as the release logger. */
    539         RTLogRelSetDefaultInstance(g_pLoggerRelease);
    540 #endif
    541         /* If verbosity is explicitly set, make sure to increase the logging levels for
    542          * the logging groups we offer functionality for in VBoxTray. */
    543         if (g_cVerbosity)
    544         {
    545             /* All groups we want to enable logging for VBoxTray. */
    546 #ifdef DEBUG
    547             const char *apszGroups[] = { "guest_dnd", "shared_clipboard" };
    548 #else /* For release builds we always want all groups being logged in verbose mode. Don't change this! */
    549             const char *apszGroups[] = { "all" };
    550 #endif
    551             char        szGroupSettings[_1K];
    552 
    553             szGroupSettings[0] = '\0';
    554 
    555             for (size_t i = 0; i < RT_ELEMENTS(apszGroups); i++)
    556             {
    557                 if (i > 0)
    558                     rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), "+");
    559                 if (RT_SUCCESS(rc))
    560                     rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), apszGroups[i]);
    561                 if (RT_FAILURE(rc))
    562                     break;
    563 
    564                 switch (g_cVerbosity)
    565                 {
    566                     case 1:
    567                         rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2");
    568                         break;
    569 
    570                     case 2:
    571                         rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2.l3");
    572                         break;
    573 
    574                     case 3:
    575                         rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2.l3.l4");
    576                         break;
    577 
    578                     case 4:
    579                         RT_FALL_THROUGH();
    580                     default:
    581                         rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2.l3.l4.f");
    582                         break;
    583                 }
    584 
    585                 if (RT_FAILURE(rc))
    586                     break;
    587             }
    588 
    589             LogRel(("Verbose log settings are: %s\n", szGroupSettings));
    590 
    591             if (RT_SUCCESS(rc))
    592                 rc = RTLogGroupSettings(g_pLoggerRelease, szGroupSettings);
    593             if (RT_FAILURE(rc))
    594                 RTMsgError("Setting log group settings failed, rc=%Rrc\n", rc);
    595         }
    596 
    597         /* Explicitly flush the log in case of VBOXTRAY_RELEASE_LOG=buffered. */
    598         RTLogFlush(g_pLoggerRelease);
    599     }
    600     else
    601         VBoxTrayShowError(ErrInfo.szMsg);
    602 
    603     return rc;
    604 }
    605 
    606 static void vboxTrayLogDestroy(void)
    607 {
    608     /* Only want to destroy the release logger before calling exit(). The debug
    609        logger can be useful after that point... */
    610     RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
    611 }
    612 
    613 /**
    614  * Displays an error message.
    615  *
    616  * @returns RTEXITCODE_FAILURE.
    617  * @param   pszFormat   The message text.
    618  * @param   ...         Format arguments.
    619  */
    620 RTEXITCODE VBoxTrayShowError(const char *pszFormat, ...)
    621 {
    622     va_list args;
    623     va_start(args, pszFormat);
    624     char *psz = NULL;
    625     RTStrAPrintfV(&psz, pszFormat, args);
    626     va_end(args);
    627 
    628     AssertPtr(psz);
    629     LogRel(("Error: %s", psz));
    630 
    631     MessageBox(GetDesktopWindow(), psz, "VBoxTray - Error", MB_OK | MB_ICONERROR);
    632 
    633     RTStrFree(psz);
    634 
    635     return RTEXITCODE_FAILURE;
    636 }
    637 
     499 * Destroys the invisible tool window of VBoxTray.
     500 */
    638501static void vboxTrayDestroyToolWindow(void)
    639502{
    640503    if (g_hwndToolWindow)
    641504    {
    642         Log(("Destroying tool window ...\n"));
    643 
    644505        /* Destroy the tool window. */
    645506        DestroyWindow(g_hwndToolWindow);
     
    650511}
    651512
     513/**
     514 * Creates the invisible tool window of VBoxTray.
     515 *
     516 * @returns VBox status code.
     517 */
    652518static int vboxTrayCreateToolWindow(void)
    653519{
     
    666532    {
    667533        dwErr = GetLastError();
    668         Log(("Registering invisible tool window failed, error = %08X\n", dwErr));
     534        VBoxTrayError("Registering invisible tool window failed, error = %08X\n", dwErr);
    669535    }
    670536    else
     
    697563    if (dwErr != ERROR_SUCCESS)
    698564         vboxTrayDestroyToolWindow();
    699     return RTErrConvertFromWin32(dwErr);
     565
     566    int const rc = RTErrConvertFromWin32(dwErr);
     567
     568    if (RT_FAILURE(rc))
     569        VBoxTrayError("Could not create tool window, rc=%Rrc\n", rc);
     570
     571    return rc;
    700572}
    701573
     
    782654        }
    783655    }
    784     return RTErrConvertFromWin32(dwErr);
     656
     657    int const rc = RTErrConvertFromWin32(dwErr);
     658
     659    if (RT_FAILURE(rc))
     660        VBoxTrayError("Could not setup seamless, rc=%Rrc\n", rc);
     661
     662    return rc;
    785663}
    786664
     
    800678}
    801679
     680/**
     681 * Main routine for starting / stopping all internal services.
     682 *
     683 * @returns VBox status code.
     684 */
    802685static int vboxTrayServiceMain(void)
    803686{
    804687    int rc = VINF_SUCCESS;
    805     LogFunc(("Entering vboxTrayServiceMain\n"));
     688    VBoxTrayVerbose(2, "Entering main loop\n");
    806689
    807690    g_hStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
     
    816699         * Start services listed in the vboxServiceTable.
    817700         */
    818         VBOXSERVICEENV svcEnv;
     701        VBOXTRAYSVCENV svcEnv;
    819702        svcEnv.hInstance = g_hInstance;
    820703
    821704        /* Initializes disp-if to default (XPDM) mode. */
    822705        VBoxDispIfInit(&svcEnv.dispIf); /* Cannot fail atm. */
    823     #ifdef VBOX_WITH_WDDM
     706#ifdef VBOX_WITH_WDDM
    824707        /*
    825708         * For now the display mode will be adjusted to WDDM mode if needed
    826709         * on display service initialization when it detects the display driver type.
    827710         */
    828     #endif
     711#endif
     712        VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus_Init);
    829713
    830714        /* Finally start all the built-in services! */
    831715        rc = vboxTrayServicesStart(&svcEnv);
    832         if (RT_FAILURE(rc))
    833         {
    834             /* Terminate service if something went wrong. */
    835             vboxTrayServicesStop(&svcEnv);
    836         }
    837         else
     716        if (RT_SUCCESS(rc))
    838717        {
    839718            uint64_t const uNtVersion = RTSystemGetNtVersion();
    840             rc = vboxTrayCreateTrayIcon();
    841719            if (   RT_SUCCESS(rc)
    842720                && uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Only for W2K and up ... */
     
    853731            {
    854732                /* Report the host that we're up and running! */
    855                 hlpReportStatus(VBoxGuestFacilityStatus_Active);
     733                VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus_Active);
    856734            }
    857735
     
    957835                LogFunc(("Returned from main loop, exiting ...\n"));
    958836            }
    959             LogFunc(("Waiting for services to stop ...\n"));
    960             vboxTrayServicesStop(&svcEnv);
     837
    961838        } /* Services started */
     839
     840        LogFunc(("Waiting for services to stop ...\n"));
     841
     842        VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus_Terminating);
     843
     844        vboxTrayServicesStop(&svcEnv);
     845
    962846        CloseHandle(g_hStopSem);
     847
    963848    } /* Stop event created */
    964849
    965     vboxTrayRemoveTrayIcon();
    966 
    967     LogFunc(("Leaving with rc=%Rrc\n", rc));
     850    VBoxTrayVerbose(2, "Leaving main loop with %Rrc\n", rc);
    968851    return rc;
     852}
     853
     854/**
     855 * Attaches to a parent console (if any) or creates an own (dedicated) console window.
     856 *
     857 * @returns VBox status code.
     858 */
     859static int vboxTrayAttachConsole(void)
     860{
     861    if (g_fHasConsole) /* Console already attached? Bail out. */
     862        return VINF_SUCCESS;
     863
     864    /* As we run with the WINDOWS subsystem, we need to either attach to or create an own console
     865     * to get any stdout / stderr output. */
     866    bool fAllocConsole = false;
     867    if (!AttachConsole(ATTACH_PARENT_PROCESS))
     868        fAllocConsole = true;
     869
     870    if (fAllocConsole)
     871    {
     872        if (!AllocConsole())
     873            VBoxTrayShowError("Unable to attach to or allocate a console!");
     874        /* Continue running. */
     875    }
     876
     877    RTFILE hStdIn;
     878    RTFileFromNative(&hStdIn,  (RTHCINTPTR)GetStdHandle(STD_INPUT_HANDLE));
     879    /** @todo Closing of standard handles not support via IPRT (yet). */
     880    RTStrmOpenFileHandle(hStdIn, "r", 0, &g_pStdIn);
     881
     882    RTFILE hStdOut;
     883    RTFileFromNative(&hStdOut,  (RTHCINTPTR)GetStdHandle(STD_OUTPUT_HANDLE));
     884    /** @todo Closing of standard handles not support via IPRT (yet). */
     885    RTStrmOpenFileHandle(hStdOut, "wt", 0, &g_pStdOut);
     886
     887    RTFILE hStdErr;
     888    RTFileFromNative(&hStdErr,  (RTHCINTPTR)GetStdHandle(STD_ERROR_HANDLE));
     889    RTStrmOpenFileHandle(hStdErr, "wt", 0, &g_pStdErr);
     890
     891    if (!fAllocConsole) /* When attaching to the parent console, make sure we start on a fresh line. */
     892        RTPrintf("\n");
     893
     894    g_fHasConsole = true;
     895
     896    return VINF_SUCCESS;
     897}
     898
     899/**
     900 * Detaches from the (parent) console.
     901 */
     902static void vboxTrayDetachConsole()
     903{
     904    g_fHasConsole = false;
     905}
     906
     907/**
     908 * Destroys VBoxTray.
     909 *
     910 * @returns RTEXITCODE_SUCCESS.
     911 */
     912static RTEXITCODE vboxTrayDestroy()
     913{
     914    vboxTrayDetachConsole();
     915
     916    /* Release instance mutex. */
     917    if (g_hMutexAppRunning != NULL)
     918    {
     919        CloseHandle(g_hMutexAppRunning);
     920        g_hMutexAppRunning = NULL;
     921    }
     922
     923    return RTEXITCODE_SUCCESS;
     924}
     925
     926/**
     927 * Prints the help to either a message box or a console (if attached).
     928 *
     929 * @returns RTEXITCODE_SYNTAX.
     930 * @param   cArgs               Number of arguments given via argc.
     931 * @param   papszArgs           Arguments given specified by \a cArgs.
     932 */
     933static RTEXITCODE vboxTrayPrintHelp(int cArgs, char **papszArgs)
     934{
     935    RT_NOREF(cArgs);
     936
     937    char szServices[64] = { 0 };
     938    for (size_t i = 0; i < RT_ELEMENTS(g_aServices); i++)
     939    {
     940        char szName[RTTHREAD_NAME_LEN];
     941        int rc2 = RTStrCopy(szName, sizeof(szName), g_aServices[i].pDesc->pszName);
     942        RTStrToLower(szName); /* To make it easier for users to recognize the service name via command line. */
     943        AssertRCBreak(rc2);
     944        if (i > 0)
     945        {
     946            rc2 = RTStrCat(szServices, sizeof(szServices), ", ");
     947            AssertRCBreak(rc2);
     948        }
     949        rc2 = RTStrCat(szServices, sizeof(szServices), szName);
     950        AssertRCBreak(rc2);
     951    }
     952
     953    VBoxTrayShowMsgBox(VBOX_PRODUCT " - " VBOX_VBOXTRAY_TITLE,
     954                       MB_ICONINFORMATION,
     955                       VBOX_PRODUCT " %s v%u.%u.%ur%u\n"
     956                       "Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n\n"
     957                       "Command Line Parameters:\n\n"
     958                       "-d, --debug\n"
     959                       "    Enables debugging mode\n"
     960                       "-f, --foreground\n"
     961                       "    Enables running in foreground\n"
     962                       "-l, --logfile <file>\n"
     963                       "    Enables logging to a file\n"
     964                       "-v, --verbose\n"
     965                       "    Increases verbosity\n"
     966                       "-V, --version\n"
     967                       "   Displays version number and exit\n"
     968                       "-?, -h, --help\n"
     969                       "   Displays this help text and exit\n"
     970                       "\n"
     971                       "Service parameters:\n\n"
     972                       "--enable-<service-name>\n"
     973                       "   Enables the given service\n"
     974                       "--disable-<service-name>\n"
     975                       "   Disables the given service\n"
     976                       "--only-<service-name>\n"
     977                       "   Only starts the given service\n"
     978                       "\n"
     979                       "Examples:\n"
     980                       "  %s -vvv --logfile C:\\Temp\\VBoxTray.log\n"
     981                       "  %s --foreground -vvvv --only-draganddrop\n"
     982                       "\n"
     983                       "Available services: %s\n\n",
     984                       VBOX_VBOXTRAY_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV,
     985                       papszArgs[0], papszArgs[0], szServices);
     986
     987    vboxTrayDestroy();
     988
     989    return RTEXITCODE_SYNTAX;
    969990}
    970991
     
    977998    if (RT_FAILURE(rc))
    978999        return RTMsgInitFailure(rc);
     1000
     1001    /* If a debugger is present, we always want to attach a console. */
     1002    if (IsDebuggerPresent())
     1003        vboxTrayAttachConsole();
    9791004
    9801005    /*
     
    9831008    static const RTGETOPTDEF s_aOptions[] =
    9841009    {
     1010        { "--debug",            'd',                         RTGETOPT_REQ_NOTHING },
     1011        { "/debug",             'd',                         RTGETOPT_REQ_NOTHING },
     1012        { "--foreground",       'f',                         RTGETOPT_REQ_NOTHING },
     1013        { "/foreground",        'f',                         RTGETOPT_REQ_NOTHING },
    9851014        { "--help",             'h',                         RTGETOPT_REQ_NOTHING },
    9861015        { "-help",              'h',                         RTGETOPT_REQ_NOTHING },
     
    10061035        {
    10071036            case 'h':
    1008                 hlpShowMessageBox(VBOX_PRODUCT " - " VBOX_VBOXTRAY_TITLE,
    1009                                   MB_ICONINFORMATION,
    1010                      "-- " VBOX_PRODUCT " %s v%u.%u.%ur%u --\n\n"
    1011                      "Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n\n"
    1012                      "Command Line Parameters:\n\n"
    1013                      "-l, --logfile <file>\n"
    1014                      "    Enables logging to a file\n"
    1015                      "-v, --verbose\n"
    1016                      "    Increases verbosity\n"
    1017                      "-V, --version\n"
    1018                      "   Displays version number and exit\n"
    1019                      "-?, -h, --help\n"
    1020                      "   Displays this help text and exit\n"
    1021                      "\n"
    1022                      "Examples:\n"
    1023                      "  %s -vvv\n",
    1024                      VBOX_VBOXTRAY_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV,
    1025                      papszArgs[0], papszArgs[0]);
    1026                 return RTEXITCODE_SUCCESS;
     1037                return vboxTrayPrintHelp(cArgs, papszArgs);
     1038
     1039            case 'd':
     1040            {
     1041                /* ignore rc */ vboxTrayAttachConsole();
     1042                g_cVerbosity = 4; /* Set verbosity to level 4. */
     1043                break;
     1044            }
     1045
     1046            case 'f':
     1047            {
     1048                /* ignore rc */ vboxTrayAttachConsole();
     1049                /* Don't increase verbosity automatically here. */
     1050                break;
     1051            }
    10271052
    10281053            case 'l':
     1054            {
    10291055                if (*ValueUnion.psz == '\0')
    10301056                    szLogFile[0] = '\0';
     
    10331059                    rc = RTPathAbs(ValueUnion.psz, szLogFile, sizeof(szLogFile));
    10341060                    if (RT_FAILURE(rc))
    1035                         return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on log file path: %Rrc (%s)",
    1036                                               rc, ValueUnion.psz);
     1061                    {
     1062                        int rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on log file path: %Rrc (%s)",
     1063                                                    rc, ValueUnion.psz);
     1064                        vboxTrayDestroy();
     1065                        return rcExit;
     1066                    }
    10371067                }
    10381068                break;
     1069            }
    10391070
    10401071            case 'v':
     
    10431074
    10441075            case 'V':
    1045                 hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION,
    1046                                   "Version: %u.%u.%ur%u",
    1047                                   VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
    1048                 return RTEXITCODE_SUCCESS;
     1076                VBoxTrayShowMsgBox(VBOX_PRODUCT " - " VBOX_VBOXTRAY_TITLE,
     1077                                   MB_ICONINFORMATION,
     1078                                   "%u.%u.%ur%u", VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
     1079                return vboxTrayDestroy();
    10491080
    10501081            default:
    1051                 rc = RTGetOptPrintError(ch, &ValueUnion);
    1052                 break;
    1053         }
    1054     }
    1055 
    1056     /* Note: Do not use a global namespace ("Global\\") for mutex name here,
    1057      * will blow up NT4 compatibility! */
    1058     HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, VBOX_VBOXTRAY_TITLE);
    1059     if (   hMutexAppRunning != NULL
     1082            {
     1083                const  char *psz = ValueUnion.psz;
     1084                size_t const cch = strlen(ValueUnion.psz);
     1085                bool fFound = false;
     1086
     1087                if (cch > sizeof("--enable-") && !memcmp(psz, RT_STR_TUPLE("--enable-")))
     1088                    for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
     1089                        if ((fFound = !RTStrICmp(psz + sizeof("--enable-") - 1, g_aServices[j].pDesc->pszName)))
     1090                            g_aServices[j].fEnabled = true;
     1091
     1092                if (cch > sizeof("--disable-") && !memcmp(psz, RT_STR_TUPLE("--disable-")))
     1093                    for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
     1094                        if ((fFound = !RTStrICmp(psz + sizeof("--disable-") - 1, g_aServices[j].pDesc->pszName)))
     1095                            g_aServices[j].fEnabled = false;
     1096
     1097                if (cch > sizeof("--only-") && !memcmp(psz, RT_STR_TUPLE("--only-")))
     1098                    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
     1099                    {
     1100                        g_aServices[j].fEnabled = !RTStrICmp(psz + sizeof("--only-") - 1, g_aServices[j].pDesc->pszName);
     1101                        if (g_aServices[j].fEnabled)
     1102                            fFound = true;
     1103                    }
     1104
     1105                if (!fFound)
     1106                {
     1107                    rc = vboxTrayServicesLazyPreInit();
     1108                    if (RT_FAILURE(rc))
     1109                        break;
     1110                    for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
     1111                    {
     1112                        rc = g_aServices[j].pDesc->pfnOption(NULL, cArgs, papszArgs, NULL);
     1113                        fFound = rc == VINF_SUCCESS;
     1114                        if (fFound)
     1115                            break;
     1116                        if (rc != -1) /* Means not parsed. */
     1117                            break;
     1118                    }
     1119                }
     1120                if (!fFound)
     1121                {
     1122                    RTGetOptPrintError(ch, &ValueUnion); /* Only shown on console. */
     1123                    return vboxTrayPrintHelp(cArgs, papszArgs);
     1124                }
     1125
     1126                continue;
     1127            }
     1128        }
     1129    }
     1130
     1131    if (RT_FAILURE(rc))
     1132    {
     1133        vboxTrayDestroy();
     1134        return RTEXITCODE_FAILURE;
     1135    }
     1136
     1137    /**
     1138     * VBoxTray already running? Bail out.
     1139     *
     1140     * Note: Do not use a global namespace ("Global\\") for mutex name here,
     1141     * will blow up NT4 compatibility!
     1142     */
     1143    g_hMutexAppRunning = CreateMutex(NULL, FALSE, VBOX_VBOXTRAY_TITLE);
     1144    if (   g_hMutexAppRunning != NULL
    10601145        && GetLastError() == ERROR_ALREADY_EXISTS)
    10611146    {
    1062         /* VBoxTray already running? Bail out. */
    1063         CloseHandle (hMutexAppRunning);
    1064         hMutexAppRunning = NULL;
    1065         return RTEXITCODE_SUCCESS;
    1066     }
     1147        VBoxTrayError(VBOX_VBOXTRAY_TITLE " already running!\n");
     1148        return vboxTrayDestroy();
     1149    }
     1150
     1151    /* Set the instance handle. */
     1152#ifdef IPRT_NO_CRT
     1153    Assert(g_hInstance == NULL); /* Make sure this isn't set before by WinMain(). */
     1154    g_hInstance = GetModuleHandleW(NULL);
     1155#endif
    10671156
    10681157    rc = VbglR3Init();
    10691158    if (RT_SUCCESS(rc))
    10701159    {
    1071         rc = vboxTrayLogCreate(szLogFile[0] ? szLogFile : NULL);
     1160        rc = VBoxTrayLogCreate(szLogFile[0] ? szLogFile : NULL);
    10721161        if (RT_SUCCESS(rc))
    10731162        {
    1074             LogRel(("Verbosity level: %d\n", g_cVerbosity));
    1075 
    1076             /* Log the major windows NT version: */
    1077             uint64_t const uNtVersion = RTSystemGetNtVersion();
    1078             LogRel(("Windows version %u.%u build %u (uNtVersion=%#RX64)\n", RTSYSTEM_NT_VERSION_GET_MAJOR(uNtVersion),
    1079                     RTSYSTEM_NT_VERSION_GET_MINOR(uNtVersion), RTSYSTEM_NT_VERSION_GET_BUILD(uNtVersion), uNtVersion ));
    1080 
    1081             /* Set the instance handle. */
    1082 #ifdef IPRT_NO_CRT
    1083             Assert(g_hInstance == NULL); /* Make sure this isn't set before by WinMain(). */
    1084             g_hInstance = GetModuleHandleW(NULL);
    1085 #endif
    1086             hlpReportStatus(VBoxGuestFacilityStatus_Init);
     1163            VBoxTrayInfo("Verbosity level: %d\n", g_cVerbosity);
     1164
    10871165            rc = vboxTrayCreateToolWindow();
     1166            if (RT_SUCCESS(rc))
     1167                rc = vboxTrayCreateTrayIcon();
     1168
     1169            VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus_PreInit);
     1170
    10881171            if (RT_SUCCESS(rc))
    10891172            {
     
    11011184
    11021185                rc = vboxDtInit();
    1103                 if (!RT_SUCCESS(rc))
     1186                if (RT_FAILURE(rc))
    11041187                {
    1105                     LogFlowFunc(("vboxDtInit failed, rc=%Rrc\n", rc));
    11061188                    /* ignore the Dt Init failure. this can happen for < XP win that do not support WTS API
    11071189                     * in that case the session is treated as active connected to the physical console
     
    11101192                }
    11111193
    1112                 rc = VBoxAcquireGuestCaps(VMMDEV_GUEST_SUPPORTS_SEAMLESS | VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0, true);
    1113                 if (!RT_SUCCESS(rc))
    1114                     LogFlowFunc(("VBoxAcquireGuestCaps failed with rc=%Rrc, ignoring ...\n", rc));
    1115 
    1116                 rc = vboxTraySetupSeamless(); /** @todo r=andy Do we really want to be this critical for the whole application? */
    1117                 if (RT_SUCCESS(rc))
    1118                 {
    1119                     rc = vboxTrayServiceMain();
    1120                     if (RT_SUCCESS(rc))
    1121                         hlpReportStatus(VBoxGuestFacilityStatus_Terminating);
    1122                     vboxTrayShutdownSeamless();
    1123                 }
     1194                VBoxAcquireGuestCaps(VMMDEV_GUEST_SUPPORTS_SEAMLESS | VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0, true);
     1195
     1196                vboxTraySetupSeamless();
     1197
     1198                rc = vboxTrayServiceMain();
     1199                /* Note: Do *not* overwrite rc in the following code, as this acts as the exit code. */
     1200
     1201                vboxTrayShutdownSeamless();
    11241202
    11251203                /* it should be safe to call vboxDtTerm even if vboxStInit above failed */
     
    11301208
    11311209                VBoxCapsTerm();
    1132 
    1133                 vboxTrayDestroyToolWindow();
    1134             }
     1210            }
     1211
     1212            vboxTrayRemoveTrayIcon();
     1213            vboxTrayDestroyToolWindow();
     1214
    11351215            if (RT_SUCCESS(rc))
    1136                 hlpReportStatus(VBoxGuestFacilityStatus_Terminated);
     1216
     1217                VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus_Terminated);
    11371218            else
    1138             {
    1139                 LogRel(("Error while starting, rc=%Rrc\n", rc));
    1140                 hlpReportStatus(VBoxGuestFacilityStatus_Failed);
    1141             }
    1142 
    1143             LogRel(("Ended\n"));
    1144 
    1145             vboxTrayLogDestroy();
     1219                VBoxTrayHlpReportStatus(VBoxGuestFacilityStatus_Failed);
     1220
     1221            VBoxTrayInfo("VBoxTray terminated with %Rrc\n", rc);
     1222
     1223            VBoxTrayLogDestroy();
    11461224        }
    11471225
     
    11511229        VBoxTrayShowError("VbglR3Init failed: %Rrc\n", rc);
    11521230
    1153     /* Release instance mutex. */
    1154     if (hMutexAppRunning != NULL)
    1155     {
    1156         CloseHandle(hMutexAppRunning);
    1157         hMutexAppRunning = NULL;
    1158     }
     1231    vboxTrayDestroy();
    11591232
    11601233    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     
    12131286            {
    12141287                case TIMERID_VBOXTRAY_CHECK_HOSTVERSION:
     1288                {
    12151289                    if (RT_SUCCESS(VBoxCheckHostVersion()))
    12161290                    {
    1217                         /* After successful run we don't need to check again. */
     1291                        /* After a successful run we don't need to check again. */
    12181292                        KillTimer(g_hwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
    12191293                    }
     1294
    12201295                    return 0;
     1296                }
    12211297
    12221298                default:
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h

    r106061 r106411  
    7878
    7979/**
    80  * The environment information for services.
    81  */
    82 typedef struct VBOXSERVICEENV
     80 * The environment information for a single VBoxTray service.
     81 */
     82typedef struct VBOXTRAYSVCENV
    8383{
    8484    /** hInstance of VBoxTray. */
     
    8888     *               by the VBoxCaps facility. See #8037. */
    8989    VBOXDISPIF dispIf;
    90 } VBOXSERVICEENV;
     90} VBOXTRAYSVCENV;
    9191/** Pointer to a VBoxTray service env info structure.  */
    92 typedef VBOXSERVICEENV *PVBOXSERVICEENV;
     92typedef VBOXTRAYSVCENV *PVBOXTRAYSVCENV;
    9393/** Pointer to a const VBoxTray service env info structure.  */
    94 typedef VBOXSERVICEENV const *PCVBOXSERVICEENV;
    95 
    96 /**
    97  * A service descriptor.
    98  */
    99 typedef struct VBOXSERVICEDESC
     94typedef VBOXTRAYSVCENV const *PCVBOXTRAYSVCENV;
     95
     96/**
     97 * A VBoxTray service descriptor.
     98 */
     99typedef struct VBOXTRAYSVCDESC
    100100{
    101101    /** The service's name. RTTHREAD_NAME_LEN maximum characters. */
     
    103103    /** The service description. */
    104104    const char *pszDesc;
     105    /** The usage options stuff for the --help screen. */
     106    const char *pszUsage;
     107    /** The option descriptions for the --help screen. */
     108    const char *pszOptions;
    105109
    106110    /** Callbacks. */
     111
     112    /**
     113     * Called before parsing arguments.
     114     * @returns VBox status code.
     115     */
     116    DECLCALLBACKMEMBER(int, pfnPreInit,(void));
     117
     118    /**
     119     * Tries to parse the given command line option.
     120     *
     121     * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
     122     * @param   ppszShort   If not NULL it points to the short option iterator. a short argument.
     123     *                      If NULL examine argv[*pi].
     124     * @param   argc        The argument count.
     125     * @param   argv        The argument vector.
     126     * @param   pi          The argument vector index. Update if any value(s) are eaten.
     127     */
     128    DECLCALLBACKMEMBER(int, pfnOption,(const char **ppszShort, int argc, char **argv, int *pi));
    107129
    108130    /**
     
    116138     * @todo r=bird: The pEnv type is WRONG!  Please check all your const pointers.
    117139     */
    118     DECLCALLBACKMEMBER(int, pfnInit,(const PVBOXSERVICEENV pEnv, void **ppInstance));
     140    DECLCALLBACKMEMBER(int, pfnInit,(const PVBOXTRAYSVCENV pEnv, void **ppInstance));
    119141
    120142    /** Called from the worker thread.
     
    139161     */
    140162    DECLCALLBACKMEMBER(void, pfnDestroy,(void *pInstance));
    141 } VBOXSERVICEDESC, *PVBOXSERVICEDESC;
    142 
    143 
    144 /**
    145  * The service initialization info and runtime variables.
    146  */
    147 typedef struct VBOXSERVICEINFO
     163} VBOXTRAYSVCDESC;
     164/** Pointer to a VBoxTray service descriptor. */
     165typedef VBOXTRAYSVCDESC *PVBOXTRAYSVCDESC;
     166
     167/**
     168 * VBoxTray service initialization info and runtime variables.
     169 */
     170typedef struct VBOXTRAYSVCINFO
    148171{
    149172    /** Pointer to the service descriptor. */
    150     PVBOXSERVICEDESC pDesc;
     173    PVBOXTRAYSVCDESC pDesc;
    151174    /** Thread handle. */
    152175    RTTHREAD         hThread;
     
    164187    /** Whether the service is enabled or not. */
    165188    bool             fEnabled;
    166 } VBOXSERVICEINFO, *PVBOXSERVICEINFO;
    167 
    168 /**
    169  * Globally unique (system wide) message registration.
    170  */
    171 typedef struct VBOXGLOBALMESSAGE
     189} VBOXTRAYSVCINFO;
     190/** Pointer to a VBoxTray service' initialization and runtime variables. */
     191typedef VBOXTRAYSVCINFO *PVBOXTRAYSVCINFO;
     192
     193/**
     194 * Structure for keeping a globally registered Windows message.
     195 */
     196typedef struct VBOXTRAYGLOBALMSG
    172197{
    173198    /** Message name. */
     
    181206     *  to be filled in when registering the actual message. */
    182207    UINT     uMsgID;
    183 } VBOXGLOBALMESSAGE, *PVBOXGLOBALMESSAGE;
    184 
     208} VBOXTRAYGLOBALMSG;
     209/** Pointer to a globally registered Windows message. */
     210typedef VBOXTRAYGLOBALMSG *PVBOXTRAYGLOBALMSG;
    185211
    186212/*********************************************************************************************************************************
    187213*   Externals                                                                                                                    *
    188214*********************************************************************************************************************************/
    189 extern VBOXSERVICEDESC g_SvcDescDisplay;
     215extern VBOXTRAYSVCDESC g_SvcDescDisplay;
    190216#ifdef VBOX_WITH_SHARED_CLIPBOARD
    191 extern VBOXSERVICEDESC g_SvcDescClipboard;
     217extern VBOXTRAYSVCDESC g_SvcDescClipboard;
    192218#endif
    193 extern VBOXSERVICEDESC g_SvcDescSeamless;
    194 extern VBOXSERVICEDESC g_SvcDescVRDP;
    195 extern VBOXSERVICEDESC g_SvcDescIPC;
    196 extern VBOXSERVICEDESC g_SvcDescLA;
     219extern VBOXTRAYSVCDESC g_SvcDescSeamless;
     220extern VBOXTRAYSVCDESC g_SvcDescVRDP;
     221extern VBOXTRAYSVCDESC g_SvcDescIPC;
     222extern VBOXTRAYSVCDESC g_SvcDescLA;
    197223#ifdef VBOX_WITH_DRAG_AND_DROP
    198 extern VBOXSERVICEDESC g_SvcDescDnD;
     224extern VBOXTRAYSVCDESC g_SvcDescDnD;
    199225#endif
    200226
    201 extern int          g_cVerbosity;
     227extern bool         g_fHasConsole;
     228extern unsigned     g_cVerbosity;
    202229extern HINSTANCE    g_hInstance;
    203230extern HWND         g_hwndToolWindow;
    204231extern uint32_t     g_fGuestDisplaysChanged;
    205232
    206 RTEXITCODE VBoxTrayShowError(const char *pszFormat, ...);
    207 
    208233#endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxTray_h */
    209234
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTrayInternal.h

    r106061 r106411  
    104104                             DWORD aBitsPerPixel, LONG aPosX, LONG aPosY, BOOL fEnabled, BOOL fExtDispSup);
    105105
     106int                      VBoxTrayLogCreate(const char *pszLogFile);
     107void                     VBoxTrayLogDestroy(void);
     108
     109void                     VBoxTrayInfo(const char *pszFormat, ...);
     110RTEXITCODE               VBoxTrayError(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     111void                     VBoxTrayVerbose(unsigned iLevel, const char *pszFormat, ...)  RT_IPRT_FORMAT_ATTR(2, 3);
     112RTEXITCODE               VBoxTrayShowError(const char *pszFormat, ...);
     113
    106114#endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxTrayInternal_h */
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp

    r106061 r106411  
    7979typedef struct VBOXVRDPCONTEXT
    8080{
    81     const VBOXSERVICEENV *pEnv;
     81    const VBOXTRAYSVCENV *pEnv;
    8282
    8383    uint32_t level;
     
    279279}
    280280
    281 static DECLCALLBACK(int) VBoxVRDPInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     281/**
     282 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     283 */
     284static DECLCALLBACK(int) vbtrVRDPPreInit(void)
     285{
     286    return VINF_SUCCESS;
     287}
     288
     289/**
     290 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     291 */
     292static DECLCALLBACK(int) vbtrVRDPOption(const char **ppszShort, int argc, char **argv, int *pi)
     293{
     294    RT_NOREF(ppszShort, argc, argv, pi);
     295
     296    return -1;
     297}
     298
     299/**
     300 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     301 */
     302static DECLCALLBACK(int) vbtrVRDPInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    282303{
    283304    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
     
    316337}
    317338
     339/**
     340 * @interface_method_impl{VBOXSERVICEDESC,pfnDestroy}
     341 */
    318342static DECLCALLBACK(void) VBoxVRDPDestroy(void *pInstance)
    319343{
     
    335359
    336360/**
    337  * Thread function to wait for and process mode change requests
    338  */
    339 static DECLCALLBACK(int) VBoxVRDPWorker(void *pvInstance, bool volatile *pfShutdown)
     361 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
     362 */
     363static DECLCALLBACK(int) vbtrVRDPWorker(void *pvInstance, bool volatile *pfShutdown)
    340364{
    341365    AssertPtrReturn(pvInstance, VERR_INVALID_POINTER);
     
    450474 * The service description.
    451475 */
    452 VBOXSERVICEDESC g_SvcDescVRDP =
     476VBOXTRAYSVCDESC g_SvcDescVRDP =
    453477{
    454478    /* pszName. */
     
    456480    /* pszDescription. */
    457481    "VRDP Connection Notification",
     482    /* pszUsage. */
     483    NULL,
     484    /* pszOptions. */
     485    NULL,
    458486    /* methods */
    459     VBoxVRDPInit,
    460     VBoxVRDPWorker,
     487    vbtrVRDPPreInit,
     488    vbtrVRDPOption,
     489    vbtrVRDPInit,
     490    vbtrVRDPWorker,
    461491    NULL /* pfnStop */,
    462492    VBoxVRDPDestroy
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.h

    r106061 r106411  
    3333
    3434/* The restore service prototypes. */
    35 int                VBoxVRDPInit    (const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread);
     35int                VBoxVRDPInit    (const VBOXTRAYSVCENV *pEnv, void **ppInstance, bool *pfStartThread);
    3636unsigned __stdcall VBoxVRDPThread  (void *pInstance);
    37 void               VBoxVRDPDestroy (const VBOXSERVICEENV *pEnv, void *pInstance);
     37void               VBoxVRDPDestroy (const VBOXTRAYSVCENV *pEnv, void *pInstance);
    3838
    3939#endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxVRDP_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