Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 24-08-2005 5: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