![]() TheWin32 subsystem shown next to thePOSIX andOS/2 subsystem in thearchitecture of Windows NT (laterWin64 is also available.) | |
Developer(s) | Microsoft |
---|---|
Initial release | November 20, 1985; 39 years ago (1985-11-20) |
Operating system | Microsoft Windows,OS/2 |
Predecessor | DOS API |
Type | API |
License | Proprietary |
Website | learn |
TheWindows API, informallyWinAPI, is the foundationalapplication programming interface (API) that allows acomputer program to access the features of theMicrosoft Windowsoperating system in which the program is running. Programs can access API functionality viashared-library technologies or viasystem-file access.[disputed –discuss]
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 asoftware development kit,Microsoft Windows SDK, which includes documentation and tools for building software based on the Windows API.
![]() | This section needs to beupdated. The reason given is: The categories are out of date, as are the references for it; see, for example,https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list.. Please help update this article to reflect recent events or newly available information.(May 2023) |
This section lists notable services provided by the Windows API.[1]
Base services include features such as thefile system,devices,processes,threads, anderror handling. These functions reside inkernel.exe,krnl286.exe orkrnl386.exe files on 16-bit Windows, andkernel32.dll and KernelBase.dll on 32 and 64 bit Windows. These files reside in the folder\Windows\System32 on all versions of Windows.[2]
Advanced services include features beyond the kernel like theWindows registry, shutdown/restart the system (or abort), start/stop/create aWindows service, manage user accounts. These functions reside inadvapi32.dll andadvapires32.dll on 32-bit Windows.
TheGraphics Device Interface (GDI) component provides features to output graphics content tomonitors,printers, and otheroutput devices. It resides ingdi.exe on 16-bit Windows, andgdi32.dll on 32-bit Windows in user-mode. Kernel-mode GDI support is provided bywin32k.sys
which communicates directly with the graphics driver.[3][4]
TheUser Interface component provides features to create and manage screenwindows and most basic controls, such asbuttons andscrollbars, receive mouse and keyboard input, and other functions associated with thegraphical user interface (GUI) part of Windows. This functional unit resides inuser.exe on 16-bit Windows, anduser32.dll on 32-bit Windows. SinceWindows XP versions, the basic controls reside incomctl32.dll, together with the common controls (Common Control Library).[5]
The Common Dialog Box Library provides standarddialog boxes to open and save files, choose color and font, etc. The library resides in a file calledcommdlg.dll on 16-bit Windows, andcomdlg32.dll on 32-bit Windows. It is grouped under theUser Interface category of the API.[6]
The Common Control Library provides access to advanced user interface controls include things likestatus bars,progress bars,toolbars andtabs. The library resides in a DLL file calledcommctrl.dll on 16-bit Windows, andcomctl32.dll on 32-bit Windows. It is grouped under theUser Interface category of the API.[7]
The Windows Shell component provides access to theoperating system shell. The component resides inshell.dll on 16-bit Windows, andshell32.dll on 32-bit Windows. The Shell Lightweight Utility Functions are inshlwapi.dll. It is grouped under theUser Interface category of the API.[8][9]
Network Services provide access to the variousnetworking abilities of the operating system. Its subcomponents includeNetBIOS,Winsock,NetDDE,remote procedure call (RPC) and many more. This component resides innetapi32.dll on 32-bit Windows.[10]
TheInternet Explorer (IE) web browser exposes APIs and as such could be considered part of the Windows API. IE has been included with the operating system sinceWindows 95 OSR2 and has provided web-related services to applications sinceWindows 98.[11]
The Windows API is aC language-based API.[12] Functions and data structures are consumable via C syntax by includingwindows.h, but the API can be consumed via any programming language that can inter-operate with the API data structures andcalling conventions forfunction calls andcallbacks.
Of note, the implementation of API functions has been developed in several languages other than C.[a]
Despite the fact that C is not anobject-oriented programming (OOP) 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++ — seeMicrosoft Foundation Class Library (MFC),Visual Component Library (VCL),GDI+. Of note,Windows 8 provides the Windows API and theWinRT API, which is implemented inC++[13] and is object-oriented by design.[13]
Windows.pas is aDelphi unit that exposes the features of Windows API – thePascal equivalent ofwindows.h.[14]
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 aswrapping 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 theWindows startup process use theNative API instead.[15]
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 agraphical 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<stdio.h>intmain(void){printf("Hello, World!\n");}
Charles Petzold, who wrote several books about programming for the Windows API, said: "The originalhello 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."[16] 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.[17]
Over the years, various changes and additions were made to Windows systems, and the Windows API changed and grew to reflect this.[18] The Windows API forWindows 1.0 supported fewer than 450function 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.[19]
Microsoft has made an effort to maintainbackward compatibility. To achieve this, when developing new versions of Windows, Microsoft sometimes implemented workarounds[20] 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 (often in spite of themselves). 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."[21]
One of the largest changes to the Windows API was the transition from Win16 (shipped in Windows 3.1 and older) toWin32 (Windows NT and Windows 95 and up). While Win32 was originally introduced withWindows NT 3.1 andWin32s 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 APIthunks was used that could allow 32-bit code to call into 16-bit code (for most of Win16 APIs) 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-bitWindows are also able to run 32-bit applications viaWoW64. The SysWOW64 folder located in the Windows folder on the OS drive contains several tools to support 32-bit applications.[22]
Each version of Microsoft Windows contains a version of Windows API, and almost every new version of Microsoft Windows has introduced additions and changes to the Windows API.[23]
The name, Windows API, refers to essentially the same capability in each version of Windows, but there is another name for this capability that is based on major architectural aspects of the Windows version that contains it. When there was only one version, it was simply called Windows API. Then, when the first major update was made, Microsoft gave it the name Win32 and gave the first version the name Win16. The term Windows API refers to both versions and all subsequently developed major versions.[24]
TheWine project provides a Win32 APIcompatibility layer forUnix-like platforms, betweenLinux kernel API and programs written for the Windows API.ReactOS goes a step further and aims to implement the full Windows operating system, working closely with the Wine project to promote code re-use and compatibility.DosWin32 andHX DOS Extender are other projects which emulate the Windows API to allow executing simple Windows programs from aDOS command line.Odin is a project to emulate Win32 onOS/2, superseding the original Win-OS/2 emulation which was based on Microsoft code. Other minor implementations include the MEWEL andZinc libraries which were intended to implement a subset of the Win16 API on DOS (seeList of platform-independent GUI libraries).
Windows Interface Source Environment (WISE) was a licensing program from Microsoft which allowed developers to recompile and run Windows-based applications onUnix andMacintosh platforms. WISE SDKs were based on an emulator of the Windows API that could run on those platforms.[28]
Efforts toward standardization included Sun'sPublic Windows Interface (PWI) for Win16 (see also: Sun Windows Application Binary Interface (Wabi)), Willows Software'sApplication Programming Interface for Windows (APIW) for Win16 and Win32 (see also:Willows TWIN), andECMA-234, which attempted to standardize the Windows API bindingly.
To develop software that uses the Windows API, a compiler must be able to use the Microsoft-specific DLLs listed above (COM-objects are outside Win32 and assume a certain vtable layout). The compiler must either handle the header files that expose the interior API function names, or supply such files.
For the language C++, Zortech (laterSymantec, thenDigital Mars),Watcom andBorland have all produced well known commercial compilers that have been used often with Win16, Win32s, and Win32. Some of them suppliedmemory extenders, allowing Win32 programs to run on Win16 with Microsoft's redistributable Win32s DLL. The Zortech compiler was probably one of the first stable and usable C++ compilers for Windows programming, before Microsoft had a C++ compiler.
For certain classes of applications, the compiler system should also be able to handleinterface description language (IDL) files. Collectively, these prerequisites (compilers, tools, libraries, and headers) are known as theMicrosoft Platform SDK. For a time, the MicrosoftVisual Studio andBorland's integrated development system were the onlyintegrated development environments (IDEs) that could provide this (although, the SDK is downloadable for free separately from the entire IDE suite, fromMicrosoft Windows SDK for Windows 7 and .NET Framework 4).
As of 2016[update], theMinGW andCygwin projects also provide such an environment based on theGNU Compiler Collection (GCC), using a stand-alone header file set, to make linking against the Win32-specific DLLs simple.LCC-Win32 is a C compiler maintained by Jacob Navia,freeware for non-commercial use.Pelles C is a freeware C compiler maintained by Pelle Orinius.Free Pascal is afree softwareObject Pascal compiler that supports the Windows API. The MASM32 package is a mature project providing support for the Windows API underMicrosoft Macro Assembler (MASM) by using custom made or converted headers and libraries from the Platform SDK. Flat assemblerFASM allows building Windows programs without using an external linker, even when running on Linux.
Windows specific compiler support is also needed forStructured Exception Handling (SEH). This system serves two purposes: it provides a substrate on which language-specificexception handling can be implemented, and it is how the kernel notifies applications of exceptional conditions such as dereferencing an invalid pointer or stack overflow. The Microsoft/Borland C++ compilers had the ability to use this system as soon as it was introduced in Windows 95 and NT, however the actual implementation was undocumented and had to be reverse engineered for the Wine project and free compilers. SEH is based on pushing exception handler frames onto the stack, then adding them to a linked list stored inthread-local storage (the first field of the thread environment block). When an exception is thrown, the kernel and base librariesunwind the stack running handlers and filters as they are encountered. Eventually, every exception unhandled by the application will be dealt with by the default backstop handler, which pops up the Windows common crash dialog.