Basic question about Win32 API programming in C

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.
 
1,981
5
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.
 

Hurkyl

Staff Emeritus
Science Advisor
Gold Member
14,829
14
WINAPI is a macro; if you were feeling industrious, you could go searching through the header files, looking for where it is defined.
 
157
1
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..
 

The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top