Basic question about Win32 API programming in C

  • Thread starter Thread starter chingkui
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary
The discussion centers on the syntax of the WinMain function in Win32 API programming in C, specifically the role of "WINAPI." "WINAPI" is a macro that defines the calling convention for the function, which is crucial for how the function interacts with the Windows operating system. It is not part of the C standard but is specific to Win32 applications. While some participants note that "WINAPI" is primarily a calling convention, others clarify that it can be applied to any function or function pointer, suggesting that there may be alternative entry points for Win32 applications that do not use this convention.
chingkui
Messages
178
Reaction score
2
I have a very basic question about Win32 API programming in C, I am trying to understand the following syntax:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}

While "int" specifies the return type of WinMain, what does "WINAPI" in between "int" and "WinMain" do? Is this syntax a part of C standard?

Thanks.
 
Technology news on Phys.org
chingkui said:
I have a very basic question about Win32 API programming in C, I am trying to understand the following syntax:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}

While "int" specifies the return type of WinMain, what does "WINAPI" in between "int" and "WinMain" do? Is this syntax a part of C standard?

Thanks.
It has nothing to do with C, it is simply a calling convention for Win32 programs to refer to the program entry point.
 
WINAPI is a macro; if you were feeling industrious, you could go searching through the header files, looking for where it is defined.
 
MeJennifer said:
It has nothing to do with C, it is simply a calling convention for Win32 programs to refer to the program entry point.

This is not strictly true. WINAPI is just a define for a calling convention, the fact that the entry point uses this calling convention is not really important. You can use WINAPI for any function or function pointer. It think it is also possible to have a Win32 entry-point which does not use this calling convention, but I am not 100% sure, will have to test that when I get home today..
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
6K
Replies
1
Views
2K
  • · Replies 28 ·
Replies
28
Views
4K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
1
Views
3K
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K