Just a sidenote, though main() (or WinMain) is called every time a program starts, its actually not the entry point function on windows.
mainCRTStartup and WinMainCRTStartup are the real entry functions on windows. This is because of the standard C library msvc ships with.
Code:
int main()
{
return 0;
}
The above code will generate a 31KB PE with msvc. This is because the compiler will cram the C runtime in the application.
Now here is how you make main() the real entry point and tell msvc to forget about the standard library:
Code:
#pragma comment(linker, "/DEFAULTLIB:kernel32.lib")
#pragma comment(linker, "/ENTRY:main")
#include <windows.h>
char Hello[] = "Hello there!\n";
DWORD dwChars;
int main()
{
HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
WriteConsoleA(hConOut, Hello, sizeof(Hello)-1, &dwChars, NULL);
ReadConsoleA(hConIn, Hello, 1, &dwChars, NULL);
return 0;
}
Above code resulted in a 3KB executable, much better. I used kernel32 as the defaultlib, because all the functions for my little hello world are in there. To have no library at all, you can pass "/NODEFAULTLIB" to the linker. Keep in mind though that the C runtime is not usable now. So no printf, no malloc and so on.