Thread: How does windows.h change the main entry function to WinMain()?

  1. #1
    Registered User
    Join Date
    Jan 2020
    Posts
    6

    How does windows.h change the main entry function to WinMain()?

    I do not understand this. All C programs must start at the main() function, right? But how does Win32 applications change it to using WinMain() instead? Why does it not use main()?

    What is happening behind the scenes?

    Code:
    #include <windows.h>
    
    
    int WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
    {
        MessageBox(NULL, "Hello, Windows!", "Hello", MB_OK);
    }

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    671
    The compiled final code isn't just YOUR code. There is an initialization and finalization codes as well. This 'initialization' code calls main(), in console applications, but Windows calls WinMain() on "windows" applications.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 01-31-2014, 03:52 AM
  2. how to change it into one main() function code..
    By transgalactic2 in forum C Programming
    Replies: 10
    Last Post: 12-13-2008, 10:02 PM
  3. WinMain entry point in .lib
    By cloudy in forum Windows Programming
    Replies: 8
    Last Post: 10-28-2006, 12:16 PM
  4. Replies: 10
    Last Post: 07-14-2003, 05:30 PM
  5. WinMain? main?
    By thanatos in forum Windows Programming
    Replies: 5
    Last Post: 05-22-2002, 04:12 AM

Tags for this Thread