Windows API

Source: Wikipedia, the free encyclopedia.

Windows API
Developer(s)Microsoft
Initial releaseNovember 20, 1985; 38 years ago (1985-11-20)
Operating systemMicrosoft Windows, OS/2
PredecessorDOS API
TypeAPI
LicenseProprietary
Websitehttps://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.

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
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
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
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
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
NetDDE, remote procedure call (RPC) and many more. This component resides in netapi32.dll on 32-bit Windows.[10]
Web
The
Windows 95 OSR2 and has provided web-related services to applications since Windows 98.[11]
Specifically, it is used to provide:
  • An embeddable web browser control, contained in shdocvw.dll and
    mshtml.dll
    .
  • The URL moniker service, held in urlmon.dll, which provides COM objects to applications for resolving URLs. Applications can also provide their own URL handlers for others to use.
  • An HTTP client library which also takes into account system-wide Proxy settings (wininet.dll); however, Microsoft has added another HTTP client library called winhttp.dll which is smaller and more suitable for some applications.
  • A library to assist multi-language and international text support (mlang.dll).
  • DirectX Transforms, a set of image filter components.
  • XML support (the MSXML components, held in msxml*.dll).
  • Access to the Windows Address Books.

Program interaction

The Windows API is defined in the

function calls and callbacks
.

Of note, the internal implementation of the API functions has been developed in several languages other than C.[a]

Despite the fact that C is not an

WinRT API, which is implemented in C++[13] and is object-oriented by design.[13]

Windows.pas is a

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.

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, 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>

int main(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.

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.

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

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

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

The

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
).

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

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

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

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[update], the

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. 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. Windows XP 64-bit Edition, Windows Advanced Server 2003 for Itanium and Windows 2008 Advanced Server for Itanium on the IA-64
    platform.

References

  1. ^ a b 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. ^ .
  14. .
  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. 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

External links