VirtualBox

Changeset 98343 in vbox


Ignore:
Timestamp:
Jan 30, 2023 11:11:47 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155571
Message:

FE/SDL: Attach or allocate a console, now that we're running on the WINDOWS subsystem. Also re-route the standard output handles to the parent handles, if available. ​bugref:9449

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r98306 r98343  
    3232*********************************************************************************************************************************/
    3333#define LOG_GROUP LOG_GROUP_GUI
     34
     35#include <iprt/stream.h>
    3436
    3537#include <VBox/com/com.h>
     
    27922794    if (RT_FAILURE(rc))
    27932795        return RTMsgInitFailure(rc);
    2794     return TrustedMain(argc, argv, NULL);
     2796
     2797#ifdef RT_OS_WINDOWS
     2798    /* As we run with the WINDOWS subsystem, we need to either attach to or create an own console
     2799     * to get any stdout / stderr output. */
     2800    bool fAllocConsole = ::IsDebuggerPresent();
     2801    if (!fAllocConsole)
     2802    {
     2803        if (!AttachConsole(ATTACH_PARENT_PROCESS))
     2804            fAllocConsole = true;
     2805    }
     2806
     2807    if (fAllocConsole)
     2808    {
     2809        if (!AllocConsole())
     2810            MessageBox(GetDesktopWindow(), L"Unable to attach to or allocate a console!", L"VBoxSDL", MB_OK | MB_ICONERROR);
     2811        /* Continue running. */
     2812    }
     2813
     2814    RTFILE hStdOut;
     2815    RTFileFromNative(&hStdOut,  (RTHCINTPTR)GetStdHandle(STD_OUTPUT_HANDLE));
     2816    /** @todo Closing of standard handles not support via IPRT (yet). */
     2817    RTStrmOpenFileHandle(hStdOut, "wt", 0, &g_pStdOut);
     2818
     2819    RTFILE hStdErr;
     2820    RTFileFromNative(&hStdErr,  (RTHCINTPTR)GetStdHandle(STD_ERROR_HANDLE));
     2821    RTStrmOpenFileHandle(hStdErr, "wt", 0, &g_pStdErr);
     2822
     2823    if (!fAllocConsole) /* When attaching to the parent console, make sure we start on a fresh line. */
     2824        RTPrintf("\n");
     2825#endif /* RT_OS_WINDOWS */
     2826
     2827    int rcExit = TrustedMain(argc, argv, NULL);
     2828
     2829#ifdef RT_OS_WINDOWS
     2830    FreeConsole(); /* Detach or destroy (from) console. */
     2831#endif
     2832
     2833    return rcExit;
    27952834}
    27962835#endif /* !VBOX_WITH_HARDENING */
Note: See TracChangeset for help on using the changeset viewer.

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