Glossary of Computer Science and Engineering Part 11 - Application Programming Interface | HackTHatCORE

Glossary of Computer Science and Engineering Part 11 - Application Programming Interface | HackTHatCORE
API

Application Programming Interface (API)

In order for an application program to function, it must interact with the computer system in a variety of ways, such as reading information from disk files, sending data to the printer, and displaying text and graphics on the monitor screen (see user interface ). The program may need to find out whether a device is available or whether it can have access to an additional portion of memory. In order to pro- vide these and many other services, an operating system such as Microsoft Windows includes an extensive applica- tion program interface (API). The API basically consists of a variety of functions or procedures that an application pro- gram can call upon, as well as data structures, constants, and various definitions needed to describe system resources. Applications programs use the API by including calls to routines in a program library (see library , program and procedures and functions ). In Windows, “dynamic link libraries” (DLLs) are used. For example, this simple func- tion puts a message box on the screen:


MessageBox (0, “Program Initialization Failed!”,
“Error!”, MB_ICONEXCLAMATION | MB_OK | MB_
SYSTEMMODAL);

     

In practice, the API for a major operating system such as Windows contains hundreds of functions, data structures, and definitions. In order to simplify learning to access the necessary functions and to promote the writing of readable code, compiler developers such as Microsoft and Borland have devised frameworks of C++ classes that package related functions together. For example, in the Microsoft Founda- tion Classes (MFC), a program generally begins by deriving a class representing the application’s basic characteristics from the MFC class CWinApp. When the program wants to display a window, it derives it from the CWnd class, which has the functions common to all windows, dialog boxes, and controls. From CWnd is derived the specialized class for each type of window: for example, CFrameWnd imple- ments a typical main application window, while CDialog would be used for a dialog box. Thus in a framework such as MFC or Borland’s OWL, the object-oriented concept of encapsulation is used to bundle together objects and their functions, while the concept of inheritance is used to relate the generic object (such as a window) to specialized ver- sions that have added functionality (see object - oriented programming and encapsulation inheritance ). In recent years Microsoft has greatly extended the reach of its Windows API by providing many higher level functions (including user interface items, network communications, and data access) previously requiring separate software com- ponents or program libraries (see M icrosoft . net ). Programmers using languages such as Visual Basic can take advantage of a further level of abstraction. Here the various kinds of windows, dialogs, and other controls are provided as building blocks that the developer can insert into a form designed on the screen, and then settings can be made and code written as appropriate to control the behavior of the objects when the program runs. While the programmer will not have as much direct control or flex- ibility, avoiding the need to master the API means that use- ful programs can be written more quickly.

References:

  • “DevCentral Tutorials: MFC and Win32.” Available online. URL: http://devcentral.iftech.com/learning/tutorials/submfc.asp. Accessed April 12, 2007.
  • Petzold, Charles. Programming Windows: the Definitive Guide to the Win32 API. 5th ed. Redmond, Wash.: Microsoft Press, 1999.
  • “Windows API Guide.” Available online. URL: http://www.vbapi. com/. Accessed April 12, 2007.

Comments