I have seen this asked 1000 times all over the forum, so ive decided to make a "How To" thread on the subject. I will try to keep this post updated with any new methods that people may have, and what IDE and compilers they work on. So feel free to email or IM me.
========== Update: Sep 17, 2005
========== IDE: VS .NET 2003, Code::Blocks Compiler: VS .NET 2003, VC Toolkit 2003
- Place this code at the very top of your main source file, when you want to remove the console window from build, just un-comment the 2nd line.
i dont see how this is improper, if you use Dev C++ it does the same thing when you check the box in project settings to remove the console window.
yes changing main to a proper winmain is the "right" way to do it, or at least that is what most people say. changng it to winmain you have to include a lot more code that must be removed for porting to linux or eventually mac, because then there is no such thing as winmain.
if there is a reason why using winmain is superior to using a main i would like to know. i just use this because i found this easier way on Microsoft's website.
[but i will still add how to change main() into a WinMain()]
Is it a win32 app intended to comply and run on windows systems? is it supposed to be developed like 99% of other games on the market? if so and it uses C++ then it uses Winmain.
Main is just a quick and easy method for teaching the basics while providing a console for debugging purposes.
You will tell me next it is ok to distribute your "Debug build" lol.
.... However. One important thing to remember here is that Irrlicht actually abstracts the "real" winmain so even when you do it the console way it should comply - it is just really bad form and therefore I fart in its general direction.
And I have no problem with console apps - what I can't understand is why you would do what you posted instead of implementing the correct way as I and Midnight stated.
If you are just messing around with stuff on your on PC then fine but if you want to be more complient then always try and do things the right way (read MS guidelines for a start)
Me again (above guest posts).
In addition - rather than having to set up a different type of app you can change it in situ with:
#ifdef _DEBUG
int main()
#else
INT WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR strCmdLine,INT)
#endif
which gives you console + console output while in debug and proper winmain in release mode "automaitically". You will also need to set your relevent compiler flags in the release/debug settings inline with the differences, but once done it is automatic and easy to have both while you develop and test!
Personally - unless you are using the parameters supplied in the WinMain (such as the HINSTANCE vars or 'show command' integer) - I see no reason why either isn't equally valid.
After all, this is a trick known & mentioned on MSDN in addition to being supported / used by other IDE's such as Dev-C++.