VC:ConsoleWindows
From GPWiki
The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server. However, the GPWiki forums are still active! Come say hello.
[edit] The ProblemAs you may know, WinMain() is the entry point for most apps built in Visual C++. This leads to portability issues right from the start of our code listing. In order to use the standard main() as the start point in Visual C++, we usually tell the compiler that we're building a console application. The problem with this approach is that there's a nasty DOS box/console window lurking around whenever our app is running. [edit] The SolutionIn order to remove the console window, we must tell the compiler that we don't need console output. This is achieved by adding the following linker command line option. /SUBSYSTEM:WINDOWS This tells Visual C++ that our program doesn't require a console window. However, the linker now assumes that it's looking for WinMain() as it's start point. If you compile your code you'll get an error something like this: error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup The fix for this is to add an additional switch: /ENTRY:mainCRTStartup This tells the compiler that main() is the start point for our app. [edit] Adding the optionsVisual C++ 6 .0 Visual C++.NET [edit] A Nice Side EffectIf we reverse the linker options to: /SUBSYSTEM:CONSOLE /ENTRY:WinMainCRTStartup We can add a console window to a native Windows application. Very handy for debugging. To remove the console window simply delete the linker options or change them to: /SUBSYSTEM:WINDOWS /ENTRY:WinMainCRTStartup Enjoy :) |


