Windows API

The Windows Application Programming Interface (short: WinAPI, English for: Windows Application Programming ) is a programming and runtime environment, which programmers is ready to create application programs for Microsoft Windows operating systems.

Details

The functions of the WinAPI are written entirely in the C and assembler, and can be used by all Windows programmers in the self-created source code. You are in libraries, the so-called DLL files such as kernel32.dll, user32.dll and gdi32.dll.

In high-level languages ​​such as C, C or Delphi, the WinAPI is always used when Windows applications are written, although the programmer they may not be called 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 provides a native API, which discloses a programming interface for both kernel-mode, as well as user-mode programs running. These interfaces are part of the operating system kernel, which ultimately all hardware-related operations carried out with and to the hardware.

The object-oriented libraries, such as the MFC library and the. NET Framework, are an alternative to using the Windows API. Here, the native methods of the Windows API are encapsulated and make possible this way, a more convenient object-oriented handling of the available functions. Many actions performed by programs, whether I / O operations, Windows dialogs or memory management be without the Windows API is very limited practicable. System Middle access to the Windows operating system, which is mainly needed device drivers is realized by using the Windows Driver Model ( WDM) under all Windows NT versions.

Versions

Almost with each new version of Microsoft Windows, the Windows API has been extended and modified. The name of the API was still maintained between versions and only slightly modified to illustrate major differences between the Windows architectures and platforms. So was the original term WinAPI which prevailed in the 16 -bit versions of Windows to the number 32 extended to Win32 API to make the significant jump to 32 -bit architecture significantly. Still today the general term Windows API is used, where also the new includes both the old API as with.

Win16

Win16 was the first API, for the 16- bit versions of Microsoft Windows. Consistent concept was simple Windows API was, but later renamed to Win16 in order to distinguish them from the newer Windows API 32- bit architecture can. 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 called libraries.

Win32

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

Although Windows CE contains a Win32 -like API, there are profound differences, make the porting of source code in reality most expensive.

Win32s

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

Win64

Win32 for 64 -bit Windows, also known as Win64, is the version of the API, the 64- bit versions of Windows - particularly 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 only two other supported platforms within the Windows NT architecture, so that both the 32 -bit and 64 -bit version of an application can be compiled from the same source code. All pointer to the memory by default 64 bits in size, so the source code may need to be checked for compatibility. Although no new features have been added to the API, there are differences between Win32 and Win64. A Win32 -compatible API through an abstraction layer called WOW64, provided - Therefore, on 64bit systems - for 32-bit applications.

. NET Framework

The. NET Framework API (formerly WinFX called ) is a new, object-oriented API that extends the native Windows API and surrounds. With version 3.0, the framework has been largely decoupled from the native WinAPI, so that a large part of the framework now consists entirely of managed code and no longer just a simple wrapper of the native WinAPI is. The API was designed, among other things, to give future applications a simple, managed access to the many new features in Windows Vista.. NET applications to run as so-called Managed Code (Managed Code ) under a runtime environment called the Common Language Runtime ( CLR), a virtual machine that performs no direct machine instructions for the purposes of abstraction, but instead converts the existing of bytecode program into machine code before this can then be executed by the processor. The GUI API set for WinFX, which is code- named Avalon, is called Windows Presentation Foundation and solves the old GDI and GDI API from. It is directly based on DirectX and graphics card with hardware acceleration needed to represent all effects appropriately.

In addition, earlier versions of Windows have also brought the APIs of other operating systems. Windows NT 3.1 and Windows NT 4.0 were still equipped with a slightly stripped-down version of the OS/2- and a POSIX API. This made it possible in a limited way to execute even programs which were compiled originally for OS / 2 or Unix systems. This was made possible by an underlying second API layer - the largely undocumented native ( native ) API. On the features of this API are encountered, for example, if you go through the operating system DLLs with a debugger. The Windows API functions from Win32, etc. call for the part in turn functions of the Native API, as well as the OS/2- and POSIX subsystem. Meanwhile, Microsoft has other APIs removed, the principal mechanism is also in Windows Vista still unchanged. With the. NET API even a third, but now much more modern object-oriented layer over the Win32 API and the Native API has been set.

Implementations outside of Windows

In addition to those contained in current Windows versions Win32/64-API of Microsoft, there are also versions for other operating systems. These replicas are intended to use Windows application programs without Windows operating system. For legal reasons, all of the original API function are usually not available, which may limit compatibility with application programs. Since most applications require all the functions of Win32/64-API, many nevertheless are fully usable.

Examples of Win32 implementations:

  • Wine: An open- source project with the goal to create a complete Win32 and Win64 API for Linux and Unix -like operating systems.
  • Cedega (formerly winex ): An almost complete commercial Win32 and DirectX implementation with the goal of making Windows games on Linux.
  • Darwine: A Wine port for Mac OS X.
  • Odin: wine32 Tells winemaker API for OS / 2
  • ReWind
  • ReactOS: Uses a part of the Wine libraries in order to save double the development work.
  • HX DOS Extender: power Win32 applications running under DOS.
  • Wabi: Windows Application Binary Interface a Win16 API project by Sun Microsystems in the early 1990s.

The Mono project provides a development environment and an API for. NET applications on Linux and Unix-like operating systems. Mono is based primarily on the Common Language Infrastructure standard.

Program Example

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

# include   LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM );   int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,                     SzCmdLine PSTR, int iCmdShow ) {     static const TCHAR szAppName [ ] = TEXT ("Class Name");     HWND hWnd;     MSG msg;     WNDCLASSEX WNDCLASSEX;       wndclassex.cbSize = sizeof ( WNDCLASSEX );     wndclassex.style = CS_HREDRAW | CS_VREDRAW;     wndclassex.lpfnWndProc = &WndProc;     wndclassex.cbClsExtra = 0;     wndclassex.cbWndExtra = 0;     wndclassex.hInstance = hInstance;     wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION );     wndclassex.hCursor = Load cursor (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 failed! ")                   szAppName, MB_OK | MB_ICONERROR );        return -1;     }       hWnd = CreateWindowEx ( WS_EX_OVERLAPPEDWINDOW, / / extended window style                    szAppName, / / window class name                    TEXT ( "Window Title " ), / / window title                    WS_OVERLAPPEDWINDOW, / / window style                    CW_USEDEFAULT, / / X position of the window                    CW_USEDEFAULT, / / y position of the window                    CW_USEDEFAULT, / / window width                    CW_USEDEFAULT, / / window height                    NULL, / / parent window                    NULL, / / menu                    hInstance, / / program - copy counter ( program ID )                    NULL); / / Additional parameters       ShowWindow ( hWnd, iCmdShow );     Update (hWnd );       for (; ;)     {        int ret = GetMessage ( & msg, NULL, 0, 0);        if ( ret == -1 )           return -1;        else if ( ret == 0)           break;        TranslateMessage ( & msg);        Dispatch Message ( & msg);     }       UnregisterClass ( szAppName, hInstance );       return ( int) msg.wParam; }   / / The main message loop LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {     HDC hdc;     PAINTSTRUCT ps;       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:         DestroyWindow ( hWnd);         break;       case WM_DESTROY:         PostQuitMessage (0);         return 0;     }       return DefWindowProc (hWnd, message, wParam, lParam); } Web Links

  • Documentation of the Win32 API ( Microsoft ) (English)
  • Complete documentation of the Win32 API (English)
  • Windows (3.1) API specification (ECMA -234 ) (English)
  • Windows32 API declarations for Basic languages ​​and ApiHelper program
  • KPD AllAPI website (English)
  • Wine project site (english)

Footnotes

  • Microsoft
  • Windows
  • Programming
  • Runtime environment
825781
de