1.write the sentenceat the preprocess as follows:
#pragma comment(linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"") //set the entry
quote from others:
VC 编写的程序,运行的时候是需要 C/C++ 运行库支持的。
当我们运行一个 C/C++ 程序的时候,链接器会首先寻找应用程序的启动函数,例如:
如果你建立了一个 console 程序的话,编译器的链接开关会是以下这种形式:
/subsystem:"console" /entry:"mainCRTStartup" (ANSI)
/subsystem:"console" /entry:"wmainCRTStartuup" (UNICODE)
如果你建立了一个win32 application,编译器的链接开关则会是以下形式:
/subsystem:"windows" /entry:"WinMain" (ANSI)
/sbusystem:"windows" /entry:"wWinMain" (UINCODE)
在默认情况下,/subsystem 和 /entry 开关是匹配的,也就是 console 对应 mainCRTStartup 或者 wmainCRTStartup;windows 对应 WinMain 或者 wWinMain。 但是我们通过手动改动的方式使他们不匹配,强制指定入口地址,即
#pragma comment(linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"")
这样运行程序的时候默认的console窗口就会隐藏!
本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/chenyusiyuan/archive/2009/09/29/4618962.aspx
2. 在IDE (VS2005/08)中设置
Project –> Properties -> Configuration Properties –> Linker -> System 中subsystem选择 /subsystem:"windows" ,在Advanced中的Entry 中填入 “mainCRTStartup” (不加任何符号)即可。