Entry Point

We write a simple program that writes text to the debugger, if any is attached.

The entry point of a Windows application is [WinMain](<https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-winmain>) instead of the traditional main function.

int __stdcall WinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nCmdShow
);

[__stdcall](<https://docs.microsoft.com/en-us/cpp/cpp/stdcall>) is the calling convention that defines the order that parameters on the stack when the function is called.

<aside> 💡 On x64 processors, __stdcall is ignored by the compiler.

</aside>

The return value is the exit value for the application. A return value of 0 indicates that the application executed successfully.

HINSTANCE hInstance

A handle to the instance of the application.

HINSTANCE hPrevInstance

This parameter used to represent the handle to an existing application's instance in Windows 16-bit.

It is now deprecated and always set to null.

<aside> 📜 In Windows 16-bit, hPrevInstance could be checked to determine if the application was already running. There are now different methods to detect whether an application is already running (using a mutex for example).

</aside>

LPSTR lpCmdLine

The command-line arguments (excluding the program name).

int nCmdShow

A flag that indicate whether the main window should be minimized, maximized, or shown normally.

The value is used with ShowWindow and corresponds to the SW constants (SW_NORMAL).

<aside> 💡 The nCmdShow corresponds to the Run property of an application's shortcut.

</aside>

The property window for an application's shortcut

The property window for an application's shortcut

Unicode

An application compiled as a Unicode program has an alternative entry point function called wWinMain that takes a Unicode lpCmdLine parameter to receive a Unicode version of the command-line arguments.

int __stdcall wWinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  PWSTR lpCmdLine,
  int nCmdShow
);