Win32 API Background

   

The Win32 API provides numerous capabilities that are worth exploring. Allegedly, there are over 10,000 API functions available within current versions of Windows that are strewn across dozens of dynamic link libraries (DLLs). These Windows API DLLs can be found in the Windows/System directory under 95, 98, and ME, or the Windows/System32 directory under NT, 2000, and XP. Key DLLs that have been a part of Windows since 95 and NT 3.5 include the Windows kernel library ( kernel32.dll ), the user library ( user32.dll ), and the graphical device interface (GDI) library ( gdi32.dll ).

Also important are some of the extensions and support libraries that have been added by Microsoft as Windows has evolved. Examples include the multimedia system library ( mmsystem.dll ), the Windows Shell library ( shell32.dll ), the Windows Internet Extensions library ( wininet.dll ), Windows Sockets ( winsock.dll and wsock32.dll ), DirectX libraries, and many more. Many of these extensions and support libraries are not necessarily required for Windows to work, but provide useful features that make programs more robust and powerful.

TIP

The Win32 API functions that are made natively available to the Borland developer reside in an import library called import32.lib . This library is linked into each project that is built. To view the functions contained in this import library use Borland's TLIB command-line tool as follows :

 TLIB import32.lib, import32.txt 

This will produce a file called import32.txt that contains a list of the Win32 modules and the functions provided by each of those modules. Although it might appear to be lengthy when you view import32.txt , it's not an exhaustive list of the Win32 API. A number of other Win32 API modules and functions might never make it into the import32.lib , which is produced with each release of C++Builder. To utilize other Win32 API modules, you must locate the DLL that supports the desired feature and either use the implib command-line tool to create a library that can be supported by the Borland compiler and linker, or dynamically load a DLL using the LoadLibary() call.

To discover the list of available functions and services supported by a specific Win32 API library, try using Borland's impdef command-line tool to generate an interface definition ( .def ) file of the DLL, as shown in the following example:

 impdef a user32.def user32.dll 

When using this command-line utility, or any other one that requires a filename, be sure to supply the full path to the dll file or position your active directory in the folder the dll resides. The .def file, which can be viewed by any text editor, will contain a list of available functions that can be used by application developers. Browsing the windows/system (95, 98, Me) or windows/system32 (NT, 2000, XP) directory will reveal a plethora of DLLs, yet only a small percentage of these DLLs are true Win32 API DLLs. Often, a Win32 DLL will contain a 32 tag embedded within the filename. The Properties feature (see Figure 14.2) within Windows Explorer can be used to reveal more information about the DLL. If it says Microsoft and says API , you can be certain it's a Win32 API module.

Figure 14.2. The DLL Properties dialog.

graphics/14fig02.gif

Alternatively, an example utility called "DLL LIB Util" is included on the book CD-ROM, which automates the steps described previously in displaying information regarding a specified DLL or LIB file (see Figure 14.3). The source code for this program is provided on the CD-ROM and utilizes several Win32 API calls for discovering information regarding Windows files such as a DLL.

Figure 14.3. DLL LIB utility.

graphics/14fig03.jpg


Within C++Builder and Delphi, many of the common Win32 API features have been wrapped within the core set of VCL components used to help construct a typical Windows application. VCL Win32 examples include TEdit , TLabel , TMemo , TRichEdit , TImageList , TTreeView , TOpenDialog , Ttimer , and much more. In fact, many of the visual VCL components that are derived from TWinControl are simply wrappers to Microsoft Windows screen objects. In addition, several other non-visual VCL components provide other Win32 API support such as TTimer .

Although the VCL provides an object-oriented “based interface to the Win32 API, it is not all inclusive. Many of the Win32 API functions and features have not made their way into a VCL component. As a result, there are Win32 functions and features that are often untapped by the C++Bulder (and Delphi) developer.

Let's explore these capabilities by examining each of the Win32 API functional areas.


     
Top


C++ Builder Developers Guide
C++Builder 5 Developers Guide
ISBN: 0672319721
EAN: 2147483647
Year: 2002
Pages: 253

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net