Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does WINAPI stand for

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 . :)

like image 591
Videron Avatar asked Nov 19 '12 22:11

Videron


People also ask

What is WinAPI used for?

Using the Windows API, you can develop applications that run successfully on all versions of Windows while taking advantage of the features and capabilities unique to each version. (Note that this was formerly called the Win32 API.

What is WinAPI calling convention?

A calling convention is a scheme for how functions receive parameters from their caller and how they return a result. The calling conventions can differ in where parameters and return values are placed (in registers; on the call stack; a mix of both), the order they are placed.

Why is it called the Win32 API?

The modern 64-bit versions of Windows implement a native 64-bit API, and it is called "Win32". It keeps the same name because it is compatible with the 32-bit API, but it's a native 64-bit implementation, and it would make perfect sense for a 64-bit library to call itself "Win32".

Is Win32 API C or C++?

The Win32 API (also called the Windows API) is the original platform for native C/C++ Windows applications that require direct access to Windows and hardware. It provides a first-class development experience without depending on a managed runtime environment like . NET and WinRT (for UWP apps for Windows 10).


2 Answers

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.

like image 146
Roman R. Avatar answered Oct 16 '22 18:10

Roman R.


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
like image 31
Paul Rubel Avatar answered Oct 16 '22 19:10

Paul Rubel