Basic question about Win32 API programming in C

  • Thread starter chingkui
  • Start date
  • Tags
    Programming
In summary, the "WINAPI" in between "int" and "WinMain" is a calling convention for Win32 programs that refers to the program entry point. It is not specific to C and can be used for any function or function pointer.
  • #1
chingkui
181
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
  • #3
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.
 
  • #4
WINAPI is a macro; if you were feeling industrious, you could go searching through the header files, looking for where it is defined.
 
  • #5
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..
 

1. What is Win32 API programming in C?

Win32 API programming in C is a type of programming that involves using the Windows application programming interface (API) to create software applications for the Windows operating system. This API provides a set of functions and protocols for interacting with the operating system, allowing developers to create user interfaces, handle input/output operations, and perform other system tasks.

2. What are the benefits of using Win32 API programming in C?

One of the main benefits of using Win32 API programming in C is that it allows for a high degree of control and customization when developing for the Windows operating system. This can be especially useful for creating complex or specialized applications. Additionally, using the Win32 API can often result in faster and more efficient code compared to other programming methods.

3. Is Win32 API programming in C difficult to learn?

This can vary from person to person, but in general, Win32 API programming in C can be quite challenging for beginners. It requires a good understanding of the C programming language and a solid understanding of the Windows operating system. However, with practice and dedication, it is certainly possible to become proficient in Win32 API programming in C.

4. Are there any resources available for learning Win32 API programming in C?

Yes, there are many resources available for learning Win32 API programming in C. These include online tutorials, books, and forums where developers can share tips and ask for help. Additionally, there are many sample projects and code snippets available online that can help with understanding and practicing Win32 API programming in C.

5. Can I use Win32 API programming in C for other operating systems?

No, the Win32 API is specifically designed for the Windows operating system and is not compatible with other operating systems. However, there are similar APIs available for other operating systems, such as the POSIX API for Unix-based systems. Developers can also use cross-platform libraries like Qt or wxWidgets to create applications that can run on multiple operating systems.

Similar threads

  • Programming and Computer Science
Replies
31
Views
2K
  • Programming and Computer Science
Replies
16
Views
3K
Replies
1
Views
1K
  • Programming and Computer Science
Replies
28
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top