PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] How do I show the console in a c++/CLI application?

 August 17, 2022     .net, c++-cli, output, testing     No comments   

Issue

I am working on a c++/CLI application assignment in VS 2012. For testing purposes, I am trying to print some output to the console (to test methods as I build them), but there is no console window for this windows form application. Is there a way I can get the console window to show?

Or does anyone have a suggestion as to how I can display method output/results?

Thanks.

Edit - I figured out how to get the Console Window to work. Thanks David for the response.


Solution

As @David Points out, Debug::WriteLine is an excellent way to trace or send state to the output window.

System::Diagnostics::Debug::WriteLine(L" -- Object State or Tracing");

However, if you are still wanting a console window for your windows application, consider the following:

// Beginning of Application
#if _DEBUG
    if (::AllocConsole())   // <-- http://msdn.microsoft.com/en-us/library/windows/desktop/ms681952(v=vs.85).aspx
        if (!::AttachConsole(ATTACH_PARENT_PROCESS))  // -1 == ATTACH_PARENT_PROCESS or Process ID
            System::Windows::MessageBox::Show(L"Unable to attach console window", L"Error", System::Windows::MessageBoxButton::OK, System::Windows::MessageBoxImage::Exclamation);
#endif

// Application End
#if _DEBUG
    ::FreeConsole();       // <-- http://msdn.microsoft.com/en-us/library/windows/desktop/ms683150(v=vs.85).aspx
#endif

Note that this will only be seen when built using the debug configuration.

Hope this helps.



Answered By - Jeff
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing