Basic question about Win32 API programming in C

  • Thread starter Thread starter chingkui
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion revolves around the syntax and semantics of the Win32 API programming in C, specifically focusing on the "WINAPI" keyword used in the function declaration of WinMain. Participants explore its role as a calling convention and its relation to the C standard.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant asks about the purpose of "WINAPI" in the function declaration of WinMain and whether it is part of the C standard.
  • Another participant asserts that "WINAPI" is a calling convention specific to Win32 programs and is not related to the C standard.
  • A different participant mentions that "WINAPI" is a macro and suggests looking through header files for its definition.
  • One participant challenges the previous assertion by stating that while "WINAPI" is a define for a calling convention, it can be used for any function or function pointer, and questions whether a Win32 entry-point could exist without this calling convention, expressing uncertainty about this point.

Areas of Agreement / Disagreement

Participants express differing views on the relationship between "WINAPI" and the C standard, with some asserting it is unrelated while others suggest it may have broader applications. The discussion remains unresolved regarding the possibility of a Win32 entry-point without the "WINAPI" calling convention.

Contextual Notes

There are unresolved assumptions regarding the applicability of "WINAPI" beyond the context of the WinMain function and the implications of using different calling conventions in Win32 programming.

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

Similar threads

  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
8K
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