What does "WINAPI" in main function mean?

Pyjong picture Pyjong · Feb 27, 2010 · Viewed 36.7k times · Source

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?

Answer

bk1e picture bk1e · Feb 27, 2010

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.