The WinAPI Edit

The Win32 API, or WinAPI, is classified as the entire Windows library and its functions, branching from windows.h, it includes GDI (wingdi.h), and many other core windows platforms.

Most windows programs require Win32 at the core of operation, from simple windows to giant games. The WINAPI WinMain function is the Windows equivalent of int main(), and has its own syntax that all windows programs must follow. First, programs must include windows.h.

#include <windows.h>

WinMain Edit

Once windows.h is included, you must add an entry point for the program. Instead of using the familiar function int main(), you must use the WinMain function. Let's have a look at the prototype declared in the Windows API.

The prototype is: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);

Now we will break it down into its pieces.

int simply designates that the return value of the function is an Integer, just like with int main().

WINAPI is a strange tag that goes before all Win32 API function overrides. Its purpose is complicated, I won't go over it here.

WinMain is the name of the function. Its purpose is obvious.

HINSTANCE hInstance is one of the required command line arguments for the function. It specifies the application's Instance ID and is used in window creation.

HINSTANCE hPrevInstance is the ID of any previous instances of the application. This is used by screen savers and games to make sure you don't open two copies of the program at once.

LPSTR lpCmdLine is a pointer to the char array containing the command-line arguments passed to the program. This pointer can be treated like a string.

int nCmdShow is the parameters passed to the program determining how to display the window. This variable is used in window creation.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.