What does "WINAPI" in main function mean?

C++CWindowsWinapiWinmain

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

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

Solution 3 - C++

This is a macro definition intended to denote the Windows calling convention. From MSDN:

> The way the name is decorated depends > on the language and how the compiler > is instructed to make the function > available, that is, the calling > convention. The standard inter-process > calling convention for Windows used by > DLLs is known as the WinAPI > convention. It is defined in Windows > header files as WINAPI, which is in > turn defined using the Win32 > declarator __stdcall.

Solution 4 - C++

It's Windows-specific. It specifies the calling convention. WinMain gets called by Windows, and this ensures that the caller and callee agree on the calling convention.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPyjongView Question on Stackoverflow
Solution 1 - C++bk1eView Answer on Stackoverflow
Solution 2 - C++Brian R. BondyView Answer on Stackoverflow
Solution 3 - C++bobbymcrView Answer on Stackoverflow
Solution 4 - C++Jerry CoffinView Answer on Stackoverflow