what does WINAPI stand for
Asked Answered
T

3

13

I've started to learn Win32 API in C. I saw that the main function is something like

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) { .. }

but I know that a function in C is like

[ReturnType] [FunctionName] (Args) { .. }

In this case the return type is int and the function name is WinMain. So what does the WINAPI stand for and is it necessary?

Thank you . :)

Thayne answered 19/11, 2012 at 22:21 Comment(0)
L
16

It's specifying the calling convention, which is how arguments to functions are placed and managed on the stack.

You can mix calling conventions, say if you're calling some external code, like windows APIs, as long as everyone is on the same "page" with their expectations.

Typical c calls are compiled using what's known as cdecl. In cdecl the caller cleans up the arguments pushed on the stack.

WINAPI, also known as "standard call" means that the called function is responsible for cleaning up the stack of its arguments.

The MS compiler will prefix a cdecl call with a _, while a WINAPI gets a leading _ and gets an @{BYTES-NEEDED} prepended to the function name when it mangles the function names. From the link above:

call        _sumExample@8  ;WINAPI
call        _someExample   ;cdecl
Lilian answered 19/11, 2012 at 22:27 Comment(0)
R
5

It is "calling convention", defined as macro with #define and resolves to __stdcall.

Read more on 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.

Rickyrico answered 19/11, 2012 at 22:24 Comment(0)
E
-10

Win - Windows

API - Application Programming Interface

Windows Application Programming Interface

Eadith answered 23/11, 2013 at 18:41 Comment(1)
This question is rather about WINAPI calling convention than about the term itself.Ahoufe

© 2022 - 2024 — McMap. All rights reserved.