Windows API

Last updated

Windows API
Developer(s) Microsoft
Initial releaseNovember 20, 1985;38 years ago (1985-11-20)
Operating system Microsoft Windows, OS/2
Predecessor DOS API
Type API
License Proprietary
Website https://learn.microsoft.com/en-us/windows/apps/

The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running.

Contents

Each major version of the Windows API has another 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

The functions provided by the Windows API can be grouped into eight categories: [1]

Base Services
Provides access to the basic resources available to a Windows system. Included are things like file systems, 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. [2]
Advanced Services
Provides access to functions beyond the kernel. Included are things like the Windows registry, shutdown/restart the system (or abort), 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
Provides functions 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. [3] [4]
User Interface
Provides the functions 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 (GUI) 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 Control Library). [5]
Common Dialog Box Library
Provides applications the 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. [6]
Common Control Library
Gives applications access to some advanced controls provided by the operating system. These include things like status bars, progress bars, toolbars and tabs. The library resides in a dynamic-link library (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. [7]
Windows Shell
Component of the Windows API allows applications to access functions provided by the operating system shell, and to change and enhance it. 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. [8] [9]
Network Services
Give access to the various networking abilities of the operating system. Its subcomponents include NetBIOS, Winsock, NetDDE, remote procedure call (RPC) and many more. This component resides in netapi32.dll on 32-bit Windows. [10]
Web
The Internet Explorer (IE) web browser also exposes many APIs that are often used by applications, and as such could be considered a 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. [11] Specifically, it is used to provide:

Program interaction

The Windows API is defined in the C programming language. [12] Its functions and data structures are defined in C syntax (see windows.h). However, the API may 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 internal implementation of the API functions has been developed in several languages other than C. [lower-alpha 1]

Despite the fact that C is not an object-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++ -- see Microsoft Foundation Class Library (MFC), Visual Component Library (VCL), GDI+. Of note, Windows 8 provides the Windows API and the WinRT API, which is implemented in C++ [13] and is object-oriented by design. [13]

Windows.pas is a Pascal/Delphi unit that exposes the features of Windows API. It is the Pascal equivalent to the C language windows.h. [14]

The Windows API is for the most part intended for a program to access operating system features. For communication among different Windows applications, Microsoft has developed a series of technologies alongside Windows API. This started with Dynamic Data Exchange (DDE), which was superseded by Object Linking and Embedding (OLE) and later by the Component Object Model (COM), Automation Objects, ActiveX controls, and the .NET Framework. There is not always a clear distinction between these technologies, and there is much overlap.

The variety of terms is basically the result of grouping software mechanisms that relate to a given aspect of software development. Automation specifically relates to exporting the function of an application or component (as an application programming interface (API)) so that it can be controlled by other applications instead of by human users only, .NET is a self-contained general methodology and technology to develop desktop and web applications written in a variety of just-in-time (JIT) compiled languages.

Many Microsoft technologies use the Windows API -- as most software running on Windows does. As middle-ware between Windows API and an application, these technologies provide some access to Windows API. Some technologies are described as wrapping Windows API, but this is debatable since no other technology provides or exposes 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. [15]

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<stdio.h>intmain(void){printf("Hello, World!\n");}

The Windows version was still only one working line of code but it required many, many more lines of overhead. 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." [16]

Over the years, various changes and additions were made to Windows systems, and the Windows API changed and grew to reflect this. [17] 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. [18]

Microsoft has made an effort to maintain backward compatibility. To achieve this, when developing new versions of Windows, Microsoft sometimes implemented workarounds [19] 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." [20]

One of the largest changes to the Windows API was the transition from Win16 (shipped in Windows 3.1 and older) to Win32 (Windows NT and Windows 95 and up). 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 (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-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. [21]

Major versions

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. [22]

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. [1]

Other implementations

ReactOS is a free and open-source operating system that aims to implement the Windows API ReactOS Frankenstein Email.png
ReactOS is a free and open-source operating system that aims to implement the Windows API

The Wine project provides a Win32 API compatibility layer for Unix-like platforms, between Linux 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 and HX DOS Extender are other projects which emulate the Windows API to allow executing simple Windows programs from a DOS command line. Odin is a project to emulate Win32 on OS/2, superseding the original Win-OS/2 emulation which was based on Microsoft code. Other minor implementations include the MEWEL and Zinc libraries which were intended to implement a subset of the Win16 API on DOS (see List 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 on Unix and Macintosh platforms. WISE SDKs were based on an emulator of the Windows API that could run on those platforms. [26]

Efforts toward standardization included Sun's Public Windows Interface (PWI) for Win16 (see also: Sun Windows Application Binary Interface (Wabi)), Willows Software's Application Programming Interface for Windows (APIW) for Win16 and Win32 (see also: Willows TWIN), and ECMA-234, which attempted to standardize the Windows API bindingly.

Compiler support

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 (later Symantec, then Digital Mars), Watcom and Borland have all produced well known commercial compilers that have been used often with Win16, Win32s, and Win32. Some of them supplied memory 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 handle interface description language (IDL) files. Collectively, these prerequisites (compilers, tools, libraries, and headers) are known as the Microsoft Platform SDK . For a time, the Microsoft Visual Studio and Borland's integrated development system were the only integrated development environments (IDEs) that could provide this (although, the SDK is downloadable for free separately from the entire IDE suite, from Microsoft Windows SDK for Windows 7 and .NET Framework 4).

As of 2016, the MinGW and Cygwin projects also provide such an environment based on the GNU 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 a free software Object Pascal compiler that supports the Windows API. The MASM32 package is a mature project providing support for the Windows API under Microsoft Macro Assembler (MASM) by using custom made or converted headers and libraries from the Platform SDK. Flat assembler FASM allows building Windows programs without using an external linker, even when running on Linux.

Windows specific compiler support is also needed for Structured Exception Handling (SEH). This system serves two purposes: it provides a substrate on which language-specific exception 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 in thread-local storage (the first field of the thread environment block). When an exception is thrown, the kernel and base libraries unwind 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.

See also

Notes

  1. Both Pascal and x86 assembly were heavily used in earlier versions, before C became dominant. A reminiscence of this is that the API functions still use the Pascal calling convention to restore the stack from pushed parameters after a call (although they expect parameters pushed from right to left, as most C compilers do, by default).
  2. Nomenclature of released 64-bit versions includes Windows XP Professional x64 Edition and x64 Editions of Windows Server 2003, Windows Vista and Windows Server 2008 on the x86-64 (AMD64) platform, and Windows 2000 Server Limited Edition, Windows XP 64-bit Edition, Windows Advanced Server 2003 for Itanium and Windows 2008 Advanced Server for Itanium on the IA-64 platform.

Related Research Articles

<span class="mw-page-title-main">Cygwin</span> Unix-like environment for Windows

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows.

<span class="mw-page-title-main">Wine (software)</span> Windows compatibility software

Wine is a free and open-source compatibility layer to allow application software and computer games developed for Microsoft Windows to run on Unix-like operating systems. Developers can compile Windows applications against WineLib to help port them to Unix-like systems. Wine is predominantly written using black-box testing reverse-engineering, to avoid copyright issues. No code emulation or virtualization occurs. Wine is primarily developed for Linux and macOS.

The Portable Executable (PE) format is a file format for executables, object code, DLLs and others used in 32-bit and 64-bit versions of Windows operating systems, and in UEFI environments. The PE format is a data structure that encapsulates the information necessary for the Windows OS loader to manage the wrapped executable code. This includes dynamic library references for linking, API export and import tables, resource management data and thread-local storage (TLS) data. On NT operating systems, the PE format is used for EXE, DLL, SYS, MUI and other file types. The Unified Extensible Firmware Interface (UEFI) specification states that PE is the standard executable format in EFI environments.

Win32s is a 32-bit application runtime environment for the Microsoft Windows 3.1 and 3.11 operating systems. It allowed some 32-bit applications to run on the 16-bit operating system using call thunks. A beta version of Win32s was available in October 1992. Version 1.10 was released in July 1993 simultaneously with Windows NT 3.1.

<span class="mw-page-title-main">Windows 9x</span> Series of Microsoft Windows computer operating systems

Windows 9x is a generic term referring to a series of Microsoft Windows computer operating systems produced from 1995 to 2000, which were based on the Windows 95 kernel and its underlying foundation of MS-DOS, both of which were updated in subsequent versions. The first version in the 9x series was Windows 95, which was succeeded by Windows 98 and then Windows Me, which was the third and last version of Windows on the 9x line, until the series was superseded by Windows XP.

<span class="mw-page-title-main">Windows Registry</span> Database for Microsoft Windows

The Windows Registry is a hierarchical database that stores low-level settings for the Microsoft Windows operating system and for applications that opt to use the registry. The kernel, device drivers, services, Security Accounts Manager, and user interfaces can all use the registry. The registry also allows access to counters for profiling system performance.

<span class="mw-page-title-main">Phar Lap Software</span> Software company

Phar Lap Software, Inc., was a software company specializing in software development tools for DOS operating systems. The company was named after the champion New Zealand racehorse Phar Lap. They were most noted for their software allowing developers to access memory beyond the 640 KiB limit of DOS and were an author of the VCPI standard.

In computing, Windows on Windows was a compatibility layer of 32-bit versions of the Windows NT family of operating systems since 1993 with the release of Windows NT 3.1, which extends NTVDM to provide limited support for running legacy 16-bit programs written for Windows 3.x or earlier. There is a similar subsystem, known as WoW64, on 64-bit Windows versions that runs 32-bit programs.

Windows USER is a component of the Microsoft Windows operating system that provides core functionality for building simple user interfaces. The component has existed in all versions of Windows, and includes functionality for window management, message passing, input processing and standard controls.

<span class="mw-page-title-main">Architecture of Windows NT</span> Overview of the architecture of the Microsoft Windows NT line of operating systems

The architecture of Windows NT, a line of operating systems produced and sold by Microsoft, is a layered design that consists of two main components, user mode and kernel mode. It is a preemptive, reentrant multitasking operating system, which has been designed to work with uniprocessor and symmetrical multiprocessor (SMP)-based computers. To process input/output (I/O) requests, it uses packet-driven I/O, which utilizes I/O request packets (IRPs) and asynchronous I/O. Starting with Windows XP, Microsoft began making 64-bit versions of Windows available; before this, there were only 32-bit versions of these operating systems.

A dynamic-link library (DLL) is a shared library in the Microsoft Windows or OS/2 operating system.

In computer programming, the term hooking covers a range of techniques used to alter or augment the behaviour of an operating system, of applications, or of other software components by intercepting function calls or messages or events passed between software components. Code that handles such intercepted function calls, events or messages is called a hook.

The Microsoft Layer for Unicode (MSLU) is a software library for legacy versions of Windows, simplifying the creation of Unicode-aware programs on Windows 9x. It is also known as UnicoWS or by its filename, UNICOWS.DLL.

The Native API is a lightweight application programming interface (API) used by Windows NT and user mode applications. This API is used in the early stages of Windows NT startup process, when other components and APIs are still unavailable. Therefore, a few Windows components, such as the Client/Server Runtime Subsystem (CSRSS), are implemented using the Native API. The Native API is also used by subroutines such as those in kernel32.dll that implement the Windows API, the API based on which most of the Windows components are created.

Platform Invocation Services, commonly referred to as P/Invoke, is a feature of Common Language Infrastructure implementations, like Microsoft's Common Language Runtime, that enables managed code to call native code.

The Microsoft Windows operating system supports a form of shared libraries known as "dynamic-link libraries", which are code libraries that can be used by multiple processes while only one copy is loaded into memory. This article provides an overview of the core libraries that are included with every modern Windows installation, on top of which most Windows applications are built.

UWIN is a computer software package created by David Korn which allows programs written for the operating system Unix to be built and run on Microsoft Windows with few, if any, changes. Some of the software development was subcontracted to Wipro, India. References, correct or not, to the software as U/Win and AT&T Unix for Windows can be found in some cases, especially from the early days of its existence.

<span class="mw-page-title-main">Microsoft POSIX subsystem</span> Subsystem shipped with the first versions of Windows NT

Microsoft POSIX subsystem is one of four subsystems shipped with the first versions of Windows NT, the other three being the Win32 subsystem which provided the primary API for Windows NT, plus the OS/2 and security subsystems.

In computing on Microsoft platforms, WoW64 is a subsystem of the Windows operating system capable of running 32-bit applications on 64-bit Windows. It is included in all 64-bit versions of Windows, except in Windows Server Server Core where it is an optional component, and Windows Nano Server where it is not included. WoW64 aims to take care of many of the differences between 32-bit Windows and 64-bit Windows, particularly involving structural changes to Windows itself.

<span class="mw-page-title-main">Longene</span> Linux distribution

Longene is a Linux-based operating system kernel intended to be binary compatible with application software and device drivers made for Microsoft Windows and Linux. As of 1.0-rc2, it consists of a Linux kernel module implementing aspects of the Windows kernel and a modified Wine distribution designed to take advantage of the more native interface. Longene is written in the C programming language and is free and open source software. It is licensed under the terms of the GNU General Public License version 2 (GPLv2).

References

  1. 1 2 Microsoft Developer Network (July 2005). Overview of the Windows API. Retrieved August 28, 2005.
  2. Microsoft Developer Network (July 2005). Base Services. Retrieved August 28, 2005.
  3. Microsoft Developer Network (July 2005). Graphics Device Interface. Retrieved August 28, 2005.
  4. "G". Microsoft Developer Network . Retrieved January 28, 2009.
  5. Microsoft Developer Network (July 2005). User Interface. Retrieved August 28, 2005.
  6. Microsoft Developer Network (2005). Common Dialog Box Library. Retrieved September 22, 2005.
  7. Microsoft Developer Network (July 2005). Common Control Library. Retrieved August 28, 2005.
  8. Microsoft Developer Network (July 2005). Windows Shell. Retrieved August 28, 2005.
  9. Microsoft Developer Network (2005). Shell Programmer's Guide. Retrieved August 28, 2005.
  10. Microsoft Developer Network (July 2005). Network Services. Retrieved August 28, 2005.
  11. Microsoft Developer Network (January 2006); Programming and reusing the browser Retrieved January 22, 2006.
  12. "Walkthrough: Create a traditional Windows Desktop application (C++)". Microsoft Docs . February 23, 2022.
  13. 1 2 Mayberry, Michael (2012). WinRT Revealed. New York City: Apress. p. 3. ISBN   978-1-4302-4585-8.
  14. Texeira, Steve and Xavier Pacheco (2002). Borland Delphi 6 Developer's Guide. Sams. p. 253. ISBN   0672321157.
  15. Russinovich, Mark (November 2006). "Inside Native Applications". Microsoft Docs . Retrieved April 12, 2022.
  16. Charles Petzold (December 2001). Programming Microsoft Windows with C#. Microsoft Press. Beyond the Console, page 47.
  17. Detailed analysis of changes in the Windows API from XP to 10. Retrieved September 08, 2016.
  18. Charles Petzold (November 11, 1998). Programming Windows, Fifth Edition. Microsoft Press. APIs and Memory Models, page 9.
  19. Smith, Graham (October 8, 2022). "Windows 95 had special code just to fix a bug in the original SimCity". Rock, Paper, Shotgun.
  20. Raymond Chen (October 15, 2003). What about BOZOSLIVEHERE and TABTHETEXTOUTFORWIMPS? Retrieved June 29, 2022.
  21. Hoffman, Chris. "What's the Difference Between the "System32" and "SysWOW64" Folders in Windows?". How-To Geek. Retrieved April 11, 2023.
  22. The Iseran Project (1996–2001). History of the Windows API. Retrieved October 7, 2005.
  23. "Windows XP Professional x64 Edition home page". Microsoft.
  24. "Microsoft 64-bit Computing Overview". Microsoft.
  25. "MSDN: Getting Ready for 64-bit Windows". Microsoft.
  26. WISE Archived 2008-03-30 at the Wayback Machine