VirtualBox

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


Ignore:
Timestamp:
Oct 17, 2024 8:16:26 AM (4 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
165232
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 [build fix]. ​bugref:10763

File:
1 edited

Legend:

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

    r106411 r106413  
    8080
    8181/*********************************************************************************************************************************
     82*   Structures and Typedefs                                                                                                      *
     83*********************************************************************************************************************************/
     84typedef BOOL (WINAPI *PFNALLOCCONSOLE)(VOID);
     85typedef BOOL (WINAPI *PFNATTACHCONSOLE)(DWORD);
     86
     87
     88/*********************************************************************************************************************************
    8289*   Global Variables                                                                                                             *
    8390*********************************************************************************************************************************/
     
    96103
    97104uint32_t              g_fGuestDisplaysChanged = 0;
     105
     106
     107/*********************************************************************************************************************************
     108*   Global Variables                                                                                                             *
     109*********************************************************************************************************************************/
     110DECL_HIDDEN_DATA(PFNALLOCCONSOLE)  g_pfnAllocConsole = NULL;  /* For W2K+. */
     111DECL_HIDDEN_DATA(PFNATTACHCONSOLE) g_pfnAttachConsole = NULL; /* For W2K+. */
    98112
    99113
     
    859873static int vboxTrayAttachConsole(void)
    860874{
    861     if (g_fHasConsole) /* Console already attached? Bail out. */
     875    if (    g_fHasConsole       /* Console already attached? Bail out. */
     876        || !g_pfnAttachConsole) /* AttachConsole() not available (NT <= 4.0)? */
    862877        return VINF_SUCCESS;
    863878
     
    865880     * to get any stdout / stderr output. */
    866881    bool fAllocConsole = false;
    867     if (!AttachConsole(ATTACH_PARENT_PROCESS))
     882    if (!g_pfnAttachConsole(ATTACH_PARENT_PROCESS))
    868883        fAllocConsole = true;
    869884
    870885    if (fAllocConsole)
    871886    {
    872         if (!AllocConsole())
     887        AssertPtrReturn(g_pfnAllocConsole, VERR_NOT_AVAILABLE);
     888        if (!g_pfnAllocConsole())
    873889            VBoxTrayShowError("Unable to attach to or allocate a console!");
    874890        /* Continue running. */
     
    903919{
    904920    g_fHasConsole = false;
     921}
     922
     923/**
     924 * Early initialization code, required for resolving dynamic symbols and such.
     925 *
     926 * @returns VBox status code.
     927 */
     928static int vboxTrayPreInit()
     929{
     930    RTLDRMOD hMod;
     931    int rc = RTLdrLoadSystem("kernel32.dll", true /*fNoUnload*/, &hMod);
     932    if (RT_SUCCESS(rc))
     933    {
     934        /* only W2K+, ignore rc */ RTLdrGetSymbol(hMod, "AllocConsole", (void **)&g_pfnAllocConsole);
     935        /* only W2K+, ignore rc */ RTLdrGetSymbol(hMod, "AttachConsole", (void **)&g_pfnAttachConsole);
     936
     937        RTLdrClose(hMod);
     938    }
     939
     940    return rc;
    905941}
    906942
     
    9991035        return RTMsgInitFailure(rc);
    10001036
     1037    rc = vboxTrayPreInit();
     1038    if (RT_FAILURE(rc))
     1039        return VBoxTrayShowError(VBOX_VBOXTRAY_TITLE " Pre-init failed: %Rrc\n", rc);
     1040
    10011041    /* If a debugger is present, we always want to attach a console. */
    10021042    if (IsDebuggerPresent())
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