简体   繁体   English

什么运行我的C#应用​​程序?

[英]What runs my C# application?

When developing a C# project in Visual Studio, I have three options for output type. 在Visual Studio中开发C#项目时,我有三个输出类型选项。 Console Application, Windows Application, and Class Library. 控制台应用程序,Windows应用程序和类库。 AFAIK, the only difference between a DLL and an EXE, is the EXE should have an entry point defined, and that is called when the file is double clicked. AFAIK是DLL和EXE之间的唯一区别,EXE应该定义一个入口点,并在双击文件时调用它。 However, when I launch an EXE built from a Console Application, a console window is created. 但是,当我启动从Console Application构建的EXE时,会创建一个控制台窗口。 So obviously something is happening other than the CLR getting launched and then calling my Main method. 显然,除了CLR启动然后调用我的Main方法之外,还会发生一些事情。 What launches the console window? 什么启动控制台窗口? When I launch an EXE built from a Windows Application, is some other code run also, or is it just my main method? 当我启动从Windows应用程序构建的EXE时,还运行其他一些代码,还是仅仅是我的主要方法?

Your portable executable file(exe) will contain the information about what kind of application it is. 您的可移植可执行文件(exe)将包含有关它是什么类型的应用程序的信息。

Subsystem flag of the IMAGE_OPTIONAL_HEADER defines what kind of user interface the application is built with. IMAGE_OPTIONAL_HEADER的 Subsystem标志定义了构建应用程序的用户界面类型。

IMAGE_SUBSYSTEM_WINDOWS_CUI defines the console application, IMAGE_SUBSYSTEM_WINDOWS_GUI defines the windows application and so on. IMAGE_SUBSYSTEM_WINDOWS_CUI定义控制台应用程序, IMAGE_SUBSYSTEM_WINDOWS_GUI定义Windows应用程序等。

For more information Peering Inside the PE: A Tour of the Win32 Portable Executable File Format 有关更多信息PE内部对等:Win32可移植可执行文件格式之旅

The output type is a configuration parameter for your project which tells Visual Studio what to do when you compiled. 输出类型是项目的配置参数,它告诉Visual Studio编译时要执行的操作。 If set to Console Application, it will generate an exe file with the code to launch the console window. 如果设置为Console Application,它将生成一个exe文件,其中包含启动控制台窗口的代码。

The different between a dll and an exe is more than the main method. dll和exe之间的差异不仅仅是主要方法。 Visual Studio generated additional codes in the exe file that creates the console and invoke the main method. Visual Studio在exe文件中生成了附加代码,用于创建控制台并调用main方法。 For details of how the exe file performs this, refer to http://en.wikipedia.org/wiki/Portable_Executable . 有关exe文件如何执行此操作的详细信息,请参阅http://en.wikipedia.org/wiki/Portable_Executable

In this link the inquisitor added some notes which mentioned the blog post (2nd link). 在这个链接中,调查官添加了一些提到博客文章(第二个链接)的注释。 Is it possible to build a Console app that does not display a console Window when double-clicked? 是否可以构建一个双击时不显示控制台窗口的控制台应用程序?

http://blogs.msdn.com/b/oldnewthing/archive/2009/01/01/9259142.aspx http://blogs.msdn.com/b/oldnewthing/archive/2009/01/01/9259142.aspx

The same content as Siram's answer https://stackoverflow.com/a/30084790/2005526 but to assist you with future searches these were the keywords used on google to locate the mentioned resources. 与Siram的答案https://stackoverflow.com/a/30084790/2005526相同的内容,但为了帮助您进行未来的搜索,这些是谷歌用于查找上述资源的关键字。 "double click exe launches console" “双击exe启动控制台”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM