Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "WINAPI" in main function mean?

Could you please explain to me the WINAPI word in the WinMain() function?

In the simplest way..

#include <windows.h>  int -->WINAPI<-- WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,      LPSTR lpCmdLine, int nCmdShow) {     MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);     return 0; } 

Is it just some Windows funky mode?

What does it do? Or rather what is this C++ feature I haven't encountered yet?

like image 428
Pyjong Avatar asked Feb 27 '10 18:02

Pyjong


People also ask

What is WINAPI?

WINAPI is a macro that evaluates to __stdcall , a Microsoft-specific keyword that specifies a calling convention where the callee cleans the stack. The function's caller and callee need to agree on a calling convention to avoid corrupting the stack.

What does hInstance mean?

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.

Which function in Win32 API is equivalent to the main () function of C or C++?

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.

What is the difference between main and WinMain?

WinMain() is Windows specific entry point to a Windows-based graphical application (you have windows stuff). main() is a standard C++ entry point (in Windows, it's a console based application)... That said, you can use GUI stuff in console applications and allocate console in GUI applications.


2 Answers

WINAPI is a macro that evaluates to __stdcall, a Microsoft-specific keyword that specifies a calling convention where the callee cleans the stack. The function's caller and callee need to agree on a calling convention to avoid corrupting the stack.

like image 59
bk1e Avatar answered Oct 02 '22 20:10

bk1e


WINAPI is a macro that expands to __stdcall which means that the callee cleans the stack.

like image 33
Brian R. Bondy Avatar answered Oct 02 '22 18:10

Brian R. Bondy