8
Program No. – 1 Aim: To study Windows API’s. Find out their relationship with MFC classes. Appreciate how they are helpful in finding complexities of windows programming. Introduction to API (Application Programming Interface) An application programming interface (API) is an interface implemented by a software program which enables it to interact with other software. It facilitates interaction between different software programs similar to the way the user interface facilitates interaction between humans and computers. An API is implemented by applications, libraries, and operating systems to determine their vocabularies and calling conventions, and is used to access their services. It may include specifications for routines, data structures, object classes, and protocols used to communicate between the consumer and the implementer of the API. Concept An API is an abstraction that describes an interface for the interaction with a set of functions used by components of a software system . The software providing the functions described by an API is said to be an implementation of the API. An API can be: General, the full set of an API that is bundled in the libraries of a programming language, e.g. Standard Template Library in C++ or Java API . Specific, meant to address a specific problem, e.g. Google Maps API or Java API for XML Web Services .

Vb_prac_1

Embed Size (px)

Citation preview

Page 1: Vb_prac_1

Program No. – 1

Aim: To study Windows API’s. Find out their relationship with MFC classes. Appreciate how they are helpful in finding complexities of windows programming.

Introduction to API (Application Programming Interface)

An application programming interface (API) is an interface implemented by a software program which enables it to interact with other software. It facilitates interaction between different software programs similar to the way the user interface facilitates interaction between humans and computers. An API is implemented by applications, libraries, and operating systems to determine their vocabularies and calling conventions, and is used to access their services. It may include specifications for routines, data structures, object classes, and protocols used to communicate between the consumer and the implementer of the API.

Concept

An API is an abstraction that describes an interface for the interaction with a set of functions used by components of a software system. The software providing the functions described by an API is said to be an implementation of the API.

An API can be:

General, the full set of an API that is bundled in the libraries of a programming language, e.g. Standard Template Library in C++ or Java API.

Specific, meant to address a specific problem, e.g. Google Maps API or Java API for XML Web Services.

Language-dependent, meaning it is only available by using the syntax and elements of a particular language, which makes the API more convenient to use.

Language-independent, written so that it can be called from several programming languages. This is a desirable feature for a service-oriented API that is not bound to a specific process or system and may be provided as remote procedure calls or web services. For example, a website that allows users to review local restaurants is able to layer their reviews over maps taken from Google Maps, because Google Maps has an API that facilitates this functionality. Google Maps' API controls what information a third-party site can use and how they can use it.

Page 2: Vb_prac_1

Components of API:

USER -- The USER component is Responsible for window management including messages, menus, cursors, communications, timer etc.

GDI -- The GDI component is the Graphics Device Interface; it takes care of the User Interface & Graphics Drawing, including. Windows metafiles, bitmaps, Device Context, & Fonts.

KERNEL -- The KERNEL component handles the low-level functions of memory, task, and resource mgmt that are the Heart of Windows.

Introduction to Windows Application Programming Interface

The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name Windows API more accurately reflects its roots in 16-bit Windows and its support on 64-bit Windows. Almost all Windows programs interact with the Windows API; a small number (such as programs started early in the Windows startup process) use the Native API.

Overview

The functionality provided by the Windows API can be grouped into eight categories.

1. Base Services - Provide access to the fundamental resources available to a Windows system. Included are things like file systems, devices, processes and threads, and error handling. These functions reside in kernel.exe, krnl286.exe or krnl386.exe files on 16-bit Windows, and kernel32.dll on 32-bit Windows.

2. Advanced Services - Provide access to functionality that is an addition on 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 on 32-bit Windows.

3. Graphics Device Interface - Provides functionality for outputting graphical 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.

Page 3: Vb_prac_1

4. User Interface - Provides the functionality to create and manage screen windows and most basic controls, such as buttons and scrollbars, receive mouse and keyboard input, and other functionality associated with the GUI part of Windows. This functional unit resides in user.exe on 16-bit Windows, and user32.dll on 32-bit Windows.

5. Common Dialog Box Library - Provides applications the standard dialog boxes for opening and saving files, choosing 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 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 the functionality provided by the operating system shell, as well as 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. Network Services - Give access to the various networking capabilities of the operating system. Its sub-components include NetBIOS, Winsock, NetDDE, RPC and many others.

Versions

Win16 is the API for the first, 16-bit versions of Microsoft Windows. These were initially referred to as simply the Windows API, but were later renamed to Win16 in an effort to distinguish it from the newer, 32-bit version of the Windows API.

Win32 is the 32-bit API for modern versions of Windows. The API consists of functions implemented, as with Win16, in system DLLs. The core DLLs of Win32 are kernel32.dll, user32.dll, and gdi32.dll. Win32 was introduced with Windows NT.

Win32s is an extension for the Windows 3.1x family of Microsoft Windows that implemented a subset of the Win32 API for these systems. The "s" stands for "subset".

Win32 for 64-bit Windows, previously known as Win64, is the variant of the API implemented on 64-bit platforms of the Windows architecture

Page 4: Vb_prac_1

MFC: Microsoft Foundation Class Library

The Microsoft Foundation Class Library (also Microsoft Foundation Classes or MFC) is a library that wraps portions of the Windows API in C++ classes, including functionality that enables them to use a default application framework. Classes are defined for many of the handle-managed Windows objects and also for predefined windows and common controls. MFC library is a collection of C++ Classes. It is provided as a DLL so your Application has access to the classes in MFC. MFC has been built using OS’s API functions. MFC allows C++ programming for Windows while API provides C Programming.

Features

MFC provided C++ macros for Windows message-handling (via Message Maps), exceptions, run-time type identification (RTTI), serialization and dynamic class instantiation.

The macros for message-handling were intended to reduce memory consumption by avoiding gratuitous virtual table use and also provide a more concrete structure for various Visual C++-supplied tools to edit and manipulate code without parsing the full language.

The message-handling macros replaced the virtual function mechanism provided by C++.

It is Easier, OOP-based, efficient than API.

MFC is an Application Frame Work, it provides a Object- Oriented Wrapper around API.

VC++ is a Visual Development tool that makes use of the MFC library to make the development under Windows environment faster & Reliable.

Its applications includes OLE visual editing, Automation, ActiveX Controls, Internet programming, Windows Common Controls, Open Database Connectivity (ODBC) Database Programming, Multithreaded Programming, Network Programming and Portability

Relationship between MFC and Windows API Programming

MFC calls functions in API. MFC interacts with OS- User, GDI & Kernel. MFC is an Application Frame Work. It provides a Object- Oriented Wrapper around API. To use MFC framework applications to be written in C++, such app can call API functions written in C. It provides C++,OOP programming interface to Windows. VC++ is a Visual Development tool that

Page 5: Vb_prac_1

makes use of the MFC library to make the development under Windows environment faster & Reliable.

Programming API

Each programming language has several APIs that communicate with Indexing Service, and you can choose the API most suitable for a task. When you choose an API, you can balance programming complexity with application performance. In general, the OLE DB Provider API is the most difficult API to program, but it is the most flexible and executes fastest. APIs that encapsulate the OLE DB Provider (such as Admin Helper or Query Helper) are easier to program, but they are less flexible and slower in execution. If you have a choice, consider this tradeoff when selecting an API.

The following table lists the APIs available for performing Indexing Service tasks and gives a brief description of each.

1. OLE DB PROVIDER :- It specializes the COM interfaces of standard Microsoft OLE DB to access Indexing Service data.

2. OLE DB HELPER :- A high-level API for querying and filtering with Indexing Service. It provides a functional interface for accessing Indexing Service data, primarily from C++ language programs.

Page 6: Vb_prac_1