Windows application programming interface

from Wikipedia, the free encyclopedia

The Windows API (abbreviated WinAPI ; English for: "Windows Application Programming Interface") is a programming and runtime environment for creating application programs for Windows - operating systems .


The functions of the WinAPI are written exclusively in the programming languages C and assembler and can be used by Windows programmers in their own source code . They are located in dynamic libraries, the so-called DLL files, for example kernel32.dll , user32.dll and gdi32.dll and are part of the operating system. The WinAPI abstracts the native functions of the operating system, which are exported by the ntdll.dll and implemented in the Windows kernel (ntoskrnl.exe). This enables Microsoft to modify the implementation of the WinAPI without changing how it works.

The WinAPI is always used when native Windows applications are written, although the programmer may not have called it directly in the source code. The calls to the API are encapsulated by a runtime library, which in turn call functions of the Windows API. Windows NT / 2000 has a native API which provides a programming interface for programs running in kernel mode as well as for programs running in user mode. These interfaces are part of the operating system kernel, which ultimately carries out all hardware-related operations with and on the hardware.

The object-oriented libraries, such as the MFC library and the .NET Framework , are an alternative to using the Windows API directly. Here, the native methods of the Windows API are encapsulated and in this way enable more convenient object-oriented handling of the available functions. Many actions performed by programs, be it I / O operations, Windows dialogs or memory management, would only be feasible to a very limited extent without the Windows API. System-level access to the Windows operating system, which is mainly required by device drivers, is implemented using the Windows Driver Model (WDM) under all Windows NT versions.


With almost every new version of Windows, the Windows API has been expanded and changed. The name of the API was retained between the versions and only slightly changed in order to illustrate the major differences between the Windows architectures and the platforms . The original term WinAPI, which prevailed in the 16-bit versions of Windows, was expanded to include the number 32 to form Win32 API, in order to make the significant leap to 32-bit architecture clear. Nevertheless, the general term Windows API is used today, which includes both the old API and the new one.


Win16 was the first API for the 16-bit versions of Windows . The common term was simply Windows API, but was later renamed Win16 to distinguish it from the newer Windows API of the 32-bit architecture. The functions of the Win16 API are mainly in the core of the operating system: kernel.exe (or krnl286.exe or krnl386.exe ), user.exe and gdi.exe . Despite the file extension exe, these files are actually so-called program libraries .


Win32 is the 32-bit - API for modern versions of Windows. The API consists of functions that, like Win16 , are implemented in program libraries. The core Win32 DLLs are kernel32.dll, user32.dll, and gdi32.dll . Win32 was introduced with Windows NT . The version of Win32, with Windows 95 was delivered, originally ran under the name Win32c, the "c" for compatibility ( English compatibility was), but the term was later discarded in favor of Microsoft Win32 again. In Windows NT and its successors (including all modern versions of Windows) Win32 calls are carried out by two modules, csrss.exe ( English Client / Server Runtime Subsystem ) in user mode and win32k.sys in the kernel mode. This serves to protect the operating system and prevents running applications of the user from modifying or accessing critical data of the operating system. The modes are provided directly by the processor.

Although Windows CE also contains a Win32-like API, there are profound differences that make porting source code in reality usually complex.


Win32s is the 32-bit API for the Windows 3.1x family and as such is the 32-bit extension for the otherwise 16-bit operating systems. The "s" stands (English for subset subset ). The function libraries from Windows NT were not completely taken over, only a selection from them, for example MS Office 97 can run under Windows NT 3.51, but not under Windows 3.1x. In combination with graphic interfaces such as OpenGL or Video for Windows , however, this should set a sufficient standard for home users by the time Windows 95 appears. It has been adapted several times and supplemented in higher version numbers.


Win32 for 64-bit Windows , also known under the name Win64 , is the version of the API that is required for 64-bit versions of Windows - namely Windows XP "x64 Edition", Windows Server 2003 "x64 Edition" (for AMD64 - Processors) and Windows Server 2003 for Itanium series - was designed. The 64-bit versions are just two other supported platforms within the Windows NT architecture, so both the 32-bit and 64-bit versions of an application can be compiled from the same source code. All pointers to the memory are by default 64 bits, which is why the source code may have to be checked for compatibility. Although no new functionality has been added to the API, there are differences between Win32 and Win64. For this reason, on 64-bit systems - for 32-bit applications - an API that is compatible with Win32 is provided by an abstraction level called WOW64 .

.NET Framework

The .NET Framework API (formerly called WinFX ) is a new, object-oriented API that extends the native Windows API. The API was designed, among other things, to give future applications easy, managed access to the many new features in Windows Vista . .NET applications run as so-called managed code under a runtime environment called Common Language Runtime (CLR), a virtual machine that, in terms of abstraction, does not execute any direct machine commands, but instead converts the program consisting of bytecode into machine code before this can then be executed by the processor. The GUI API set for WinFX, which runs under the code name Avalon , is called Windows Presentation Foundation and replaces the old GDI and GDI + APIs. It is based directly on DirectX and requires graphics cards with hardware acceleration in order to be able to display all effects appropriately.

More APIs

In addition, earlier versions of Windows brought with them the APIs of other operating systems. Windows NT 3.1 and Windows NT 4.0 were still equipped with a slightly slimmed-down version of OS / 2 and a POSIX API. This made it possible, to a limited extent, to also execute programs that were actually compiled for OS / 2 or Unix systems. This was made possible by a deeper second API layer - the largely undocumented native API . The functions of this API can be found e.g. B. If you run operating system DLLs with a debugger . Some of the Windows API functions of Win32 etc. call functions of the Native API, as does the OS / 2 and POSIX subsystem. Microsoft has since removed the other APIs, but the principle mechanism is still unchanged in Windows Vista. With the .NET API, a third, but now much more modern, object-oriented layer was set over the Win32 API and the Native API.

Implementations outside of Windows

Wine and the Win32 / 64 API in different operating systems.

In addition to the Microsoft Win32 / 64 API included in current Windows versions, there are also variants for other operating systems . These simulations are used to use Windows application programs without a Windows operating system. For legal reasons, not all functions of the original API are usually available, which can limit compatibility with application programs. Since very few application programs need all the functions of the Win32 / 64 API, many can still be fully used.

Examples of Win32 implementations:

  • Wine : An open source project with the aim of creating a complete Win32 and Win64 API for Linux and Unix- like operating systems.
  • CrossOver : A commercial extension to Wine .
  • Cedega (formerly WineX) : A nearly complete commercial Win32 and DirectX implementation with the aim of making Windows games run on Linux.
  • Darwine : A Wine port for macOS .
  • Odin : Wine32 API for OS / 2 .
  • Proton : A Wine based software with the aim of running Windows games on other platforms.
  • ReWind
  • ReactOS : Uses part of the Wine libraries to save double development work.
  • HX DOS Extender : Makes Win32 applications run under DOS.
  • Wabi : Windows Application Binary Interface a Win16 API project by Sun Microsystems from the early 1990s.

The Mono project provides a development environment and an API for .NET applications in Linux and Unix-like operating systems. Mono is primarily based on the common language infrastructure standard.

Sample program

The following source code implements a program with the help of the WinAPI, which creates a window and outputs the text " Hello World !". The program is written in the C programming language.

#include <windows.h>


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
   static TCHAR const szAppName[] = TEXT("Klassenname");
   HWND       hWnd;
   MSG        msg;
   WNDCLASSEX wndclassex;

   wndclassex.cbSize        = sizeof (WNDCLASSEX);         = CS_HREDRAW | CS_VREDRAW;
   wndclassex.lpfnWndProc   = &WndProc;
   wndclassex.cbClsExtra    = 0;
   wndclassex.cbWndExtra    = 0;
   wndclassex.hInstance     = hInstance;
   wndclassex.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
   wndclassex.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wndclassex.lpszMenuName  = NULL;
   wndclassex.lpszClassName = szAppName;
   wndclassex.hIconSm       = wndclassex.hIcon;

   if (!RegisterClassEx(&wndclassex))
      MessageBox(NULL, TEXT("RegisterClassEx fehlgeschlagen!"),
                 szAppName, MB_OK | MB_ICONERROR);
      return -1;

   hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, // erweiterter Fensterstil
                  szAppName, // Name der Fensterklasse
                  TEXT("Fenstertitel"), // Fenstertitel
                  WS_OVERLAPPEDWINDOW, // Fensterstil
                  CW_USEDEFAULT, // X-Position des Fensters
                  CW_USEDEFAULT, // Y-Position des Fensters
                  CW_USEDEFAULT, // Fensterbreite
                  CW_USEDEFAULT, // Fensterhöhe
                  NULL, // übergeordnetes Fenster
                  NULL, // Menü
                  hInstance, // Programm-Kopiezähler (Programm-ID)
                  NULL); // zusätzliche Parameter

   ShowWindow(hWnd, iCmdShow);

   while(GetMessage(&msg, NULL, 0, 0))

   UnregisterClass(szAppName, hInstance);

   return (int)msg.wParam;

// Die Hauptnachrichtenschleife
   HDC hdc;

   switch (message)
   case WM_PAINT:
       hdc = BeginPaint(hWnd, &ps);
       TextOut(hdc, 0, 0, TEXT("Hello World!"), 12);
       EndPaint(hWnd, &ps);
       return 0;

   case WM_CLOSE:

   case WM_DESTROY:
       return 0;

   return DefWindowProc(hWnd, message, wParam, lParam);


Web links

Individual evidence

  1. API Considerations. Microsoft, accessed September 2, 2013 .
  2. How to download and install Win32s using Windows 3.1 File Manager (English) - MIT , with " Win32s is an extension for the Windows 3.1 and Windows 3.11 operating systems, which allows them to run some 32-bit applications. "; last change on February 18, 1999