4

Imagine when a .NET application starts after building, either Console or WinForm. Beside the complie-time flags like /subsystem, /out, ... how does the operating system (currently Windows) or the .NET virtual machine (I don't know which happens to catch the running application, first) decide which one of the window-systems to run and what does that do when it wants to run the desired system?

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
atoipowered
  • 506
  • 4
  • 16
  • wouldn't this just determine what libraries are included by default? Can you add windows forms libraries to a console app and create and display a form? I know, a question in a question... – ps2goat Jul 15 '14 at 22:41
  • 3
    http://stackoverflow.com/q/7613880 – Robert Harvey Jul 15 '14 at 22:41
  • 1
    Strongly related (see the accepted answer): [what is the difference between win32 application, windows form application and console application?](http://stackoverflow.com/q/20592783/464709) – Frédéric Hamidi Jul 15 '14 at 22:42
  • @Robert, heh. Yours is better than mine :) – Frédéric Hamidi Jul 15 '14 at 22:42
  • @ps2goat 1-No, 2-Yes. – EZI Jul 15 '14 at 22:45
  • @EZI, yeah, I read Robert Harvey's link. Good to know, though I don't use it often. – ps2goat Jul 15 '14 at 22:45
  • @FrédéricHamidi I read every answer to those two questions. They are related stuff to mines but nor a complete answer neither an enough one to my subject. – atoipowered Jul 15 '14 at 23:27
  • 2
    @atoi, there is a flag. In the executable file itself, somewhere in the PE header. That flag is set at build time and indicates the subsystem the application wants to run under (GUI or console). The loader reads that flag and sets up a console accordingly. This predates .NET -- the CLR does not bring anything new to the picture here. – Frédéric Hamidi Jul 15 '14 at 23:35
  • @ps2goat Yes you can. If you addthe references of Windows.Forms you can create a WinForm in a console application. I have done it :P Just need to add [STAThread] and Application.Run :D – c_str Jul 15 '14 at 23:44

1 Answers1

2

I see the question has been updated to reflect this comment solution by Frédéric Hamidi, but to adhere to the Q&A format of Stack Overflow, I'm admitting this as an answer with the Community Wiki flag set, as per "Question with no answers, but issue solved in the comments (or extended in chat)."

There is a flag. In the executable file itself, somewhere in the PE header. That flag is set at build time and indicates the subsystem the application wants to run under (GUI or console). The loader reads that flag and sets up a console accordingly. This predates .NET -- the CLR does not bring anything new to the picture here.

Community
  • 1
  • 1
Matthew Haugen
  • 12,916
  • 5
  • 38
  • 54