Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Release build breaks System::Console::WriteLine()

  • 24-08-2005 05:21PM
    #1
    Closed Accounts Posts: 2


    I have a problem in calling System::Console::WriteLine() from a Release Build in Visual Studio .NET 2003 that I can't figure out.

    It is reproducable with a simple Windows Forms app that is compiled using /subsystem:windows, and thus does not have a natural console.

    In Form1.cpp, between
    System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
    Application::Run(new Form1());

    Create a new console using
    AllocConsole()
    which completes without error, and
    then i added
    System::Console::WriteLine("Hello, World!");

    If you build this in Debug Mode and start this executable via the debugger (F5) or via Explorer, then the text is output to the Console.

    If you build in Release Mode, and start the executable via the debugger, the text is again correctly output to the Console.

    if you run the Release Mode binary from Windows Explorer, the console is created (no errors returned by AllocConsole()) but nothing is printed! Nada!

    It doesn't seem to be related to buffering, because calling Flush
    System::Console::OpenStandardOutput()->Flush();
    doesn't help. I'm not interested in work arounds per se, (i.e. I have one already), but would like to know if I'm driving the framework incorrectly.


Comments

  • Closed Accounts Posts: 35 Ivan Dunaev


    don't remember exact details but some more interop needed. google for CreateFile and SetStdHandle
    it will be something like
    AllocConsole()
    C = CreateFile( "CONOUT$", ... )
    SetStdHandle( ... , C)
    Console.Writeline("...")


  • Closed Accounts Posts: 2 morph321


    yeah, I already know the console handle is good, because I can use
    GetStdHandle(STD_OUTPUT_HANDLE) and write to it.


Advertisement
Advertisement