Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do I disable the console window from showing in VC++ 12? [solved]  (Read 15380 times)

0 Members and 2 Guests are viewing this topic.

xzbobzx

  • Newbie
  • *
  • Posts: 26
    • View Profile
In VC++ 10 this was as easy as setting the SubSystem to 'Windows' instead of 'Console', but when I try it in VC12 I get this:
Quote
1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
1>I:\xzbobzx\Bobstudios\Projects\Western Game\WesternGame\Release\WesternGame.exe : fatal error LNK1120: 1 unresolved externals

What do I do?
« Last Edit: August 20, 2013, 08:11:07 pm by xzbobzx »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How do I disable the console window from showing in VC++ 12?
« Reply #1 on: August 11, 2013, 01:56:24 pm »
This is why you read the tutorials. To quote directly from the SFML and Visual studio tutorial.

Quote
If you chose to create a "Windows application" project, then the entry point of your code has to be the "WinMain" function instead of "main". Since it's Windows specific, and your code would therefore not compile on Linux or Mac OS X, SFML provides a way to keep a standard "main" entry point in this case: link your project to the sfml-main module ("sfml-main-d.lib" in Debug, "sfml-main.lib" in Release), the same way you linked sfml-graphics, sfml-window and sfml-system.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

xzbobzx

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How do I disable the console window from showing in VC++ 12?
« Reply #2 on: August 11, 2013, 02:33:55 pm »
I can't have WinMain as my release main.cpp and main as my debug main.cpp. Can I?

I always used to have a console window for the debug .exe and no console for the release one.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: How do I disable the console window from showing in VC++ 12?
« Reply #3 on: August 11, 2013, 02:43:55 pm »
You didn't read the tutorial, ok... But you could have at least read the 3 lines that zsbzsb kindly quoted for you. :/
Leave your debug config as is if you want the console, and link "sfml-main.lib" in release.

xzbobzx

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How do I disable the console window from showing in VC++ 12?
« Reply #4 on: August 18, 2013, 01:27:24 pm »
You didn't read the tutorial, ok... But you could have at least read the 3 lines that zsbzsb kindly quoted for you. :/
Leave your debug config as is if you want the console, and link "sfml-main.lib" in release.

I read the tutorials long before anyone suggested I read them, aaaand I forgot the bit about WinMain apparently. :\ Shame on me, my deepest apologies. :(

Either way, I read the tutorial again, and I followed your advice, tried it, but the console window still wouldn't budge. My project is a Console Application, not a Windows Application, so in the end WinMain isn't even of importance.

I don't understand why the console window went away so easily in vc2010 and not in vc2012 even though both projects were console applications. :\


Jonki

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: How do I disable the console window from showing in VC++ 12?
« Reply #5 on: August 18, 2013, 11:59:21 pm »
I'm guessing you still may have not fully understood what others have suggested here, but there is another solution for your problem that might be easier to grasp. Simply put this following code at the start of your program while keeping your subsystem as console:

#include <Windows.h>

int main()
{
    #ifdef NDEBUG
            HWND hwnd = GetConsoleWindow();
            ShowWindow(hwnd, SW_HIDE);
    #endif

    //...
}
 

This is far from the best solution, as it only works in Visual Studio and the console window will still appear for a second or so, but it might be enough for your purposes. =)
« Last Edit: August 19, 2013, 12:20:07 am by Jonki »
dafuq did I just write?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How do I disable the console window from showing in VC++ 12?
« Reply #6 on: August 19, 2013, 12:24:19 am »
Either way, I read the tutorial again, and I followed your advice, tried it, but the console window still wouldn't budge. My project is a Console Application, not a Windows Application, so in the end WinMain isn't even of importance.

I don't understand why the console window went away so easily in vc2010 and not in vc2012 even though both projects were console applications. :\

If you choose console as your application type you will always get the console window. This is no different for VS 2010 - so you must not be remembering that you had it set to window application to hide the console.

I'm guessing you still may have not fully understood what others have suggested here, but there is another solution for your problem that might be easier to grasp. Simply put this following code at the start of your program while keeping your subsystem as console:

This is far from the best solution, as it only works in Visual Studio and the console window will still appear for a second or so, but it might be enough for your purposes. =)

There is no point in writing such windows specific code. If you want to hide the console just change to a windows application.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

xzbobzx

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How do I disable the console window from showing in VC++ 12?
« Reply #7 on: August 19, 2013, 01:22:58 pm »
Either way, I read the tutorial again, and I followed your advice, tried it, but the console window still wouldn't budge. My project is a Console Application, not a Windows Application, so in the end WinMain isn't even of importance.

I don't understand why the console window went away so easily in vc2010 and not in vc2012 even though both projects were console applications. :\

If you choose console as your application type you will always get the console window. This is no different for VS 2010 - so you must not be remembering that you had it set to window application to hide the console.

Then, how did I have a console window in my Debug Version while I didn't have one in the release version?  :-\

I understand what you're trying to say but I know what I did, and I don't understand how it worked the way it did either.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How do I disable the console window from showing in VC++ 12?
« Reply #8 on: August 19, 2013, 01:31:57 pm »
Quote
Then, how did I have a console window in my Debug Version while I didn't have one in the release version?
Project settings > Linker > System > Sub-system. You had it to "Console" in Debug and "Windows" in Release.
Laurent Gomila - SFML developer

xzbobzx

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How do I disable the console window from showing in VC++ 12?
« Reply #9 on: August 19, 2013, 07:24:52 pm »
Quote
Then, how did I have a console window in my Debug Version while I didn't have one in the release version?
Project settings > Linker > System > Sub-system. You had it to "Console" in Debug and "Windows" in Release.

Exactly!

And (as sated in my original post) that worked in vc2010!

In vc2012 it threw my this:
Quote
1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
1>I:\xzbobzx\Bobstudios\Projects\Western Game\WesternGame\Release\WesternGame.exe : fatal error LNK1120: 1 unresolved externals

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How do I disable the console window from showing in VC++ 12?
« Reply #10 on: August 19, 2013, 08:14:34 pm »
There's no difference, really. Except in your code: when you choose "Windows" your entry point must be WinMain instead of main. If you don't want to define it, and keep a portable code, you can link to sfml-main instead.
Laurent Gomila - SFML developer

xzbobzx

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How do I disable the console window from showing in VC++ 12?
« Reply #11 on: August 20, 2013, 08:10:48 pm »
There's no difference, really. Except in your code: when you choose "Windows" your entry point must be WinMain instead of main. If you don't want to define it, and keep a portable code, you can link to sfml-main instead.

Thank you! It works perfectly. :D

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: How do I disable the console window from showing in VC++ 12? [solved]
« Reply #12 on: August 20, 2013, 10:33:11 pm »
It's exactly the same thing as the first answer, more than a week ago. ???