Dev-C The Winmain function Dev-C The Winmain function. From: Jan Mura - 2008-03-30 01:49:58. Hello, maybe it is clear but I am a little bit. Make sure you select 'Console Application' in your project's configurations. The WinMain function that is missing from your code is the 'main' function that is expected from a GUI Win32 application. If you select 'console' application, it should be looking for the 'main' function, which I presume you have defined in your 'main.c' file.
WinMain() is the C entry point function of any windows application.Like normal DOS/console based application which has main() function as C entry point, in windows we have WinMain() instead. WinMain() is a function which is called by system during creation of a process. First argument is the instance handle of the current process. Next is the previous instance. Command line arguments comes as next argument. Finally shell passes the show/display attribute of main window. WinMain returns success as zero and error as non zero.
-->Every Windows program includes an entry-point function that is named either WinMain or wWinMain. Here is the signature for wWinMain.
The four parameters are:
- hInstance is something called a 'handle to an instance' or 'handle to a module.' The operating system uses this value to identify the executable (EXE) when it is loaded in memory. The instance handle is needed for certain Windows functions—for example, to load icons or bitmaps.
- hPrevInstance has no meaning. It was used in 16-bit Windows, but is now always zero.
- pCmdLine contains the command-line arguments as a Unicode string.
- nCmdShow is a flag that says whether the main application window will be minimized, maximized, or shown normally.
The function returns an int value. The return value is not used by the operating system, but you can use the return value to convey a status code to some other program that you write.
WINAPI is the calling convention. A calling convention defines how a function receives parameters from the caller. For example, it defines the order that parameters appear on the stack. Just make sure to declare your wWinMain function as shown.
Undefined Reference To Winmain' Gcc
The WinMain function is identical to wWinMain, except the command-line arguments are passed as an ANSI string. The Unicode version is preferred. You can use the ANSI WinMain function even if you compile your program as Unicode. To get a Unicode copy of the command-line arguments, call the GetCommandLine function. This function returns all of the arguments in a single string. If you want the arguments as an argv-style array, pass this string to CommandLineToArgvW.
How does the compiler know to invoke wWinMain instead of the standard main function? What actually happens is that the Microsoft C runtime library (CRT) provides an implementation of main that calls either WinMain or wWinMain.
Note
The CRT does some additional work inside main. For example, any static initializers are called before wWinMain. Although you can tell the linker to use a different entry-point function, use the default if you link to the CRT. Otherwise, the CRT initialization code will be skipped, with unpredictable results. (For example, global objects will not be initialized correctly.)
Here is an empty WinMain function.
Now that you have the entry point and understand some of the basic terminology and coding conventions, you are ready to create a complete Window program.
Dev C++ For Windows 10
Next
Undefined Reference To Winmain Codeblocks
Module 1. Your First Windows Program.