In particular, is there a way to create a windows application without directly specifying it with the 'new project' wizard? Obviously simply including "windows.h" does not automatically create a main function, so if I wanted to create a windows application "from scratch" how would I go about doing it?
When a program starts up, the start
or _start
function is called. The definition of this function is included in a library that is usually automatically linked in. In a standard C program, it will do some start-up things and then call your main
function.
That's what happens in a standard C program, but you can use WinMain
instead, which is not standard. If main
is not present but WinMain
is, it will call WinMain
instead with the appropriate parameters.
As such, it is not necessary to have a main
function; WinMain
serves that purpose rather than main
.
icktoofay's answer is mostly right, save for one part:
That's what happens in a standard C program, but you can use
WinMain
instead, which is not standard. Ifmain
is not present butWinMain
is, it will callWinMain
instead with the appropriate parameters.
The deciding factor in what an application's secondary entry point (the function called by start
or _start
is) is which subsystem is specified to the linker.
If you're building manually, you can add the /SUBSYSTEM
switch to the linker command line to specify that you're building a Windows application (that will expect a WinMain
or wWinMain
entry point) as opposed to a console application (that will expect a main
or wmain
entry point). If you're building from Visual Studio, you can choose the subsystem in the linker settings of the C++ project properties.
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