Is it possible to call WinMain from the usual main?

In particular, is there a way to create a Windows application without directly specifying it using the β€œnew project” wizard? Obviously, just turning on windows.h does not automatically create the main function, so if I wanted to create a Windows application from scratch, how would I do it?

+4
source share
2 answers

Icktoofay's answer is basically correct, except for one part:

What happens in a standard C program, but you can use WinMain instead, which is not standard. If main not, but WinMain is, it will call WinMain instead with the appropriate parameters.

The decisive factor is that the second entry point of the application (a function called start or _start ) is the subsystem in the linker.

If you are creating manually, you can add the /SUBSYSTEM switch to the /SUBSYSTEM command line to indicate that you are creating a Windows application (which expects a WinMain or wWinMain entry WinMain ) as opposed to a console application (which expects a main or wmain entry point). If you are creating Visual Studio, you can select the subsystem in the settings of the C ++ project property linker.

+4
source

When the program starts, the start or _start function is _start . The definition of this function is included in the library, which is usually automatically linked. In a standard C program, it performs some startup function and then calls your main function.

What happens in a standard C program, but you can use WinMain instead, which is not standard. If main not, but WinMain is, it will call WinMain instead of the corresponding parameters.

Thus, there is no need to have a main function; WinMain serves this purpose, not main .

+5
source

Source: https://habr.com/ru/post/1483273/


All Articles