Windows API


The Windows API, informally WinAPI, is the foundational application programming interface that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs typically access this API using system libraries, which are shared libraries.
Each major version of the Windows API has a distinct name that identifies a compatibility aspect of that version. For example, Win32 is the major version of Windows API that runs on 32-bit systems. The name, Windows API, collectively refers to all versions of this capability of Windows.
Microsoft provides developer support via a software development kit, Microsoft Windows SDK, which includes documentation and tools for building software based on the Windows API.

Services

This section lists notable services provided by the Windows API.

Base Services

Base services include features such as the file system, devices, processes, threads, and error handling. These functions reside in kernel.exe, krnl286.exe or krnl386.exe files on 16-bit Windows, and kernel32.dll and KernelBase.dll on 32 and 64 bit Windows. These files reside in the folder \Windows\System32 on all versions of Windows.

Advanced Services

Advanced services include features beyond the kernel like the Windows registry, shutdown/restart the system, start/stop/create a Windows service, manage user accounts. These functions reside in advapi32.dll and advapires32.dll on 32-bit Windows.

Graphics Device Interface

The Graphics Device Interface component provides features to output graphics content to monitors, printers, and other output devices. It resides in gdi.exe on 16-bit Windows, and gdi32.dll on 32-bit Windows in user-mode. Kernel-mode GDI support is provided by win32k.sys which communicates directly with the graphics driver.

User Interface

The User Interface component provides features to create and manage screen windows and most basic controls, such as buttons and scrollbars, receive mouse and keyboard input, and other functions associated with the graphical user interface part of Windows. This functional unit resides in user.exe on 16-bit Windows, and user32.dll on 32-bit Windows. Since Windows XP versions, the basic controls reside in comctl32.dll, together with the common controls.

Common Dialog Box Library

The Common Dialog Box Library provides standard dialog boxes to open and save files, choose color and font, etc. The library resides in a file called commdlg.dll on 16-bit Windows, and comdlg32.dll on 32-bit Windows. It is grouped under the User Interface category of the API.

Common Control Library

The Common Control Library provides access to advanced user interface controls, including things like status bars, progress bars, toolbars and tabs. The library resides in a DLL file called commctrl.dll on 16-bit Windows, and comctl32.dll on 32-bit Windows. It is grouped under the User Interface category of the API.

Windows Shell

The Windows Shell component provides access to the operating system shell. The component resides in shell.dll on 16-bit Windows, and shell32.dll on 32-bit Windows. The Shell Lightweight Utility Functions are in shlwapi.dll. It is grouped under the User Interface category of the API.

Network Services

Network Services provide access to the various networking abilities of the operating system. Its subcomponents include NetBIOS, Winsock, NetDDE, remote procedure call and many more. This component resides in netapi32.dll on 32-bit Windows.

Web

The Internet Explorer web browser exposes APIs and as such could be considered part of the Windows API. IE has been included with the operating system since Windows 95 OSR2 and has provided web-related services to applications since Windows 98.

Program interaction

The Windows API is a C language-based API. Functions and data structures are consumable via C syntax by including windows.h, but the API can be consumed via any programming language that can inter-operate with the API data structures and calling conventions for function calls and callbacks.
Of note, the implementation of API functions has been developed in several languages other than C.
Despite the fact that C is not an object-oriented programming language, the Windows API is somewhat object-oriented due to its use of handles. Various other technologies from Microsoft and others make this object-oriented aspect more apparent by using an OOP language such as C++ — see Microsoft Foundation Class Library, Visual Component Library, GDI+. Of note, Windows 8 provides the Windows API and the WinRT API, which is implemented in C++ and is object-oriented by design.
Windows.pas is a Delphi unit that exposes the features of Windows API the Pascal equivalent of windows.h.

Related technologies

Many Microsoft technologies use the Windows API -- as most software running on Windows does. As middle-ware between Windows API and an application, the following technologies provide some access to Windows API. Some technologies are described as wrapping Windows API, but this is debatable since they don't provide or expose all of the capabilities of Windows API.
Although almost all Windows programs use the Windows API, on the Windows NT line of operating systems, programs that start early in the Windows startup process use the Native API instead.

History

The Windows API has always exposed a large part of the underlying structure of the Windows systems to programmers. This had the advantage of giving them much flexibility and power over their applications, but also creates great responsibility in how applications handle various low-level, sometimes tedious, operations that are associated with a graphical user interface.
For example, a beginning C programmer will often write the simple "hello world" as their first assignment. The working part of the program is only a single printf line within the main subroutine. The overhead for linking to the standard I/O library is also only one line:
#include
int main

Charles Petzold, who wrote several books about programming for the Windows API, said: "The original hello world program in the Windows 1.0 SDK was a bit of a scandal. HELLO.C was about 150 lines long, and the HELLO.RC resource script had another 20 or so more lines. Veteran programmers often curled up in horror or laughter when encountering the Windows hello-world program." Petzold explains that while it was the first Windows sample programs developers were introduced to, it was quite "fancy" and more complex than needed. Tired of people ridiculing the length of the sample, he eventually reduced it to a simple MessageBox call.
Over the years, various changes and additions were made to Windows systems, and the Windows API changed and grew to reflect this. The Windows API for Windows 1.0 supported fewer than 450 function calls, whereas modern versions of the Windows API support thousands. However, in general, the interface remained fairly consistent, and an old Windows 1.0 application will still look familiar to a programmer who is used to the modern Windows API.
Microsoft has made an effort to maintain backward compatibility. To achieve this, when developing new versions of Windows, Microsoft sometimes implemented workarounds to allow compatibility with third-party software that used the prior version in an undocumented or even inadvisable way. Raymond Chen, a Microsoft developer who works on the Windows API, has said: "I could probably write for months solely about bad things apps do and what we had to do to get them to work again. Which is why I get particularly furious when people accuse Microsoft of maliciously breaking applications during OS upgrades. If any application failed to run on Windows 95, I took it as a personal failure."
One of the largest changes to the Windows API was the transition from Win16 to Win32. While Win32 was originally introduced with Windows NT 3.1 and Win32s allowed use of a Win32 subset before Windows 95, it was not until Windows 95 that widespread porting of applications to Win32 began. To ease the transition, in Windows 95, for developers outside and inside Microsoft, a complex scheme of API thunks was used that could allow 32-bit code to call into 16-bit code and vice versa. Flat thunks allowed 32-bit code to call into 16-bit libraries, and the scheme was used extensively inside Windows 95's libraries to avoid porting the whole OS to Win32 in one batch. In Windows NT, the OS was pure 32-bit, except parts for compatibility with 16-bit applications, and only generic thunks were available to thunk from Win16 to Win32, as for Windows 95. The Platform SDK shipped with a compiler that could produce the code needed for these thunks. Versions of 64-bit Windows are also able to run 32-bit applications via WoW64. The SysWOW64 folder located in the Windows folder on the OS drive contains several tools to support 32-bit applications.