views:

149

answers:

4

hi guys,

could you please explain to me the WINAPI word in winmain header ?

in the simpliest 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..

+7  A: 

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.

bk1e
so why is it in this specific place? couldn't they give the macro one line above?
stupid_idiot
The calling convention keyword goes between the return type and the function name because that's how someone working on a C compiler defined it many years ago. I don't know the reasoning behind the syntax, or even which compiler was the first to support specifying calling conventions (cdecl, pascal, fortran, etc.). Microsoft? Borland? Lattice? Something else?
bk1e
+2  A: 

WINAPI just means __stdcall

Brian R. Bondy
+2  A: 

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.

bobbymcr
+1  A: 

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.

Jerry Coffin