I use that "gui console" code a lot for debugging. But I have found that clicking on the console's [x] button, to close it, can sometimes take out the app. So if you need the console for more than just debugging, you might want to look into disabling the close button. This involves calls to GetConsoleWindow(), GetSystemMenu(), and DeleteMenu().