這是我在《Programming Microsoft Windows with C#》(此書(shū)作者是大名鼎鼎的Charles Petzold)一書(shū)中找到的描述:
This compiler switch doesn't do anything very profound. It really only sets a flag in the executable file that indicates how the program is to be loaded an run. If an executable is flagged as a Console Application and is started from Windows, the Windows operating system creates a Command Prompt window that launches the program and displays any console output from the program. If the console application is started from within the Command Prompt window, the MS-DOS promptdoesn't return until the program terminateds. If the executable is flagged as a Windows Application, no Command Prompt window is created. Any console output from the program goes into the bit bucket. If you start such a program from the Command Prompt window, the MS-DOS prompt appears again right after the program is launched. The point is this: nothing bad happens if you compile a Windows Forms application as a console application!
作者之前提到的編譯選項(xiàng)是/target:exe和/target:winexe,前者生成控制臺(tái)程序,后者生成Windows程序,這是C#的編譯器,而VC++的連接器的選項(xiàng)卻有些不同,看這張圖:

如果你在應(yīng)用程序向?qū)Ю镏付ǖ氖且粋€(gè)Windows程序,而你后來(lái)卻在這個(gè)連接器選項(xiàng)里選擇Console,那會(huì)怎么樣呢?——會(huì)連接失敗!因?yàn)閂C++連接器認(rèn)為Console程序和Windows程序的入口函數(shù)是不同,這樣簡(jiǎn)單的一改它會(huì)找不到入口函數(shù),所以連接失敗。
但不管這樣,通過(guò)Charles Petzold的這段描述,我們對(duì)Console程序和Windows程序的認(rèn)識(shí)應(yīng)該是沒(méi)什么問(wèn)題了,兩者其實(shí)并沒(méi)有什么根本不同,只是Windows根據(jù)PE文件中的標(biāo)識(shí),用稍微不同的方法來(lái)運(yùn)行這兩種程序而已。
BTW:Windows程序可以創(chuàng)建自己的控制臺(tái)(參考AllocConsole等API),控制臺(tái)程序也可以創(chuàng)建窗口。