When I start a new project in Visual Studio, I have a few options to choose from: Windows application, console application, dll, static library. What exactly are the differences and when should I use which? (Sorry if this is a stupid question, I am new to C++.) Thanks in advance.
Console application.
Create an executable program ([.exe] file) with console subsystem. This means that each running program instance will be outfitted with an associated console window. Either an existing one or a new one.
Windows application.
Create an executable program with either console or GUI subsystem. GUI subsystem is the default. The difference from console subsystem is (only) that a console window is not automatically created when the program is run.
Static library.
This is a kind of library where the code that's used by some application, gets copied into that application's executable file.
DLL.
Dynamically linked library. This is a kind of library whose code isn't copied into each using executable file. Instead the code is dynamically placed into each running instance's memory. Due to this feature a single DLL file can be shared between many programs. Another feature is that code in a DLL can be really private and use its own runtime library.
Console versus GUI subsystem can be very easily changed in the project properties, after the project has been created.
Static library versus DLL isn't really switchable after creation.
Do note that with GUI subsystem Microsoft's linker (unlike e.g. the GCC toolchain linker) will by default not accept a standard main. To force it to accept the standard, specify entry point mainCRTStartup in the linker settings. When you use the standard project templates this must be done after project creation.
Also, if you want standard behavior then it's a good idea to turn off precompiled headers in the project creation wizard. Can be turned off also after project creation. But it's easiest and least hassle to do it already at creation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With