ATL Development   «Prev  Next»
Lesson 7 ATL project files
Objective Describe the ATL project files.

ATL Project Files

Our project has the following files.
Phbook files consists of Source Files, Header Files, Resource Files, External Dependencies
  1. Printed Text from Image:
    • Title Bar: PhBook - Microsoft Visual C++
    • Menu Bar: File, Edit, View, Insert, Project, Build, Tools, Window, Help
    • Toolbar: Contains buttons for various operations (new project, save, build, debug, etc.).
    • Workspace panel: Workspace 'PhBook': 1 project(s), PhBook files.
      • Source Files
        • PhBook.cpp
        • PhBook.def
        • PhBook.idl
        • PhBook.rc
        • PhBookObj.cpp
        • StdAfx.cpp
      • Header Files
        • PhBookObj.h
        • Resource.h
        • StdAfx.h
      • Resource Files
        • PhBookObj.rgs
      • External Dependencies
        • basedefs.h
        • PhBook.h
        • PhBook.lib
        • PhBook_i.c
  2. Relevant Features:
    • This screenshot is from Microsoft Visual C++, a popular development environment during the late 90s and early 2000s, often used for C++ application development.
    • The project name appears to be PhBook, suggesting it might be a "Phone Book" or similar application.
    • The project is structured in categories like Source Files, Header Files, Resource Files, and External Dependencies, which is a common organization in C++ development environments.
    • Source Files contains several `.cpp` files (implementation files) and `.idl` (interface definition language files).
    • Header Files contains common `.h` files (declarations of classes, functions).
    • External Dependencies includes files like PhBook.h and PhBook.lib, indicating that external libraries are being linked to the project.
    • The interface uses classic icons and UI elements typical of the late 90s-early 2000s versions of Visual C++.

This looks like a snapshot of a development environment working on a C++ project with a clear structure for handling various aspects of application development such as headers, sources, and dependencies.

  • PhBook.cpp: PhBook.cpp contains (DLL-based) server functions DllMain, DllCanUnloadNow, DllGetClassObject, DllRegisterServer, and DllUnregisterServer. It also contains the global declaration of CComModule in variable _Module and the object map.
  • PhBook.def: PhBook.def exports required functions from the DLL.

Inside COM

PhBook.idl, PhBook.h, and PhBook.tlb

PhBook.idl, PhBook.h, and PhBook.tlb contain interface definitions for IReadPhBook and IManagePhBook, type library PHBOOKLib, and COM class PhBookObj. PhBook.idl, PhBook.h, PhBook.tlb used in COM: Visual C++ automatically generates PhBook.idl to
  1. define interfaces,
  2. a type ibrary, and
  3. COM classes.
As part of the project build procedure, PhBook.idl is compiled with MIDL to create the following files:
PhBook.h defines interfaces IReadPhBook and IManagePhBook. At this time, each interface definition is empty because we have not added methods to either interface. PhBook_i.c declares variables for each IID (IID_IReadPhBook, IID_IManagePhBook), the type library (LIBID_PHBOOKLib), and the COM class (CLSID_PhBookObj).
PhBook.tlb is a type library that describes each COM interface and COM object PhBookObj and includes the interface and object IDs. The MIDL-compile step also creates PhBook_p.c and dlldata.c. These files are used when we work with out-of-process COM servers. We will not use either of these files in this course. Nor will we use file PhBookps.mak.
  • (MIDL) Interface Compiler:
    After describing your interfaces and components in IDL, you run them through the interface compiler (MIDL). The MIDL compiler takes the IDL description of your interfaces and generates several C language source files that can be used when implementing, or using, the component from C/C++. This might seem odd, since COM is supposed to be language independent. Why can't the MIDL compiler generate interface definitions for other languages? Well, instead of having to update the MIDL compiler for every new language that comes along, Microsoft chose a far more extensible approach. The solution was to have MIDL generate interface definitions in a single, universal format that all languages (including interpretative languages and macro programming environments) can understand. These are called type libraries and they are compiled, binary versions of the IDL files that can be accessed programatically. A type library file provides type information about all components, interfaces, methods, properties, arguments and structures described in an IDL file.
    In addition to the C/C++ interface definitions and the type library file, MIDL also generates proxy and stub code for the interfaces in the IDL file. Proxy/stubs are necessary when an interface is going to be accessed from another address space or across a network. These will be covered in a later section.

The relationship between eBusiness and eCommerce
Using MIDL


PhBook.rc, Resource.h, PhBookObj.rgs

PhBook.rc, Resource.h, and PhBookObj.rgs contain our application's resources. These include the compiled type library (PhBook.tlb), version information, a registry resource (discussed below), and a string table.
  • Project Resources: Files PhBook.rc and Resource.h define our project's resources. Like many MS-Windows development projects, we include version and string resources. A type library can also be included as a resource. Our type library is embedded within the DLL as a binary resource. PhBookObj.rgs is a registration script. A registration script contains commands that describe how to register our COM objects. The registration script is compiled into a binary resource and included in the executable file. The ATL framework uses the script to register and unregister the server's objects.
    Macro DECLARE_REGISTRY_RESOURCEID
    

    (IDR_PhBookObj) in PhBookObj.h adds a method called UpdateRegistry into a COM class. UpdateRegistry is used by the ATL framework to register or unregister a COM object using the registration script.

PhBookObj.cpp, PhBookObj.h

PhBookObj.cpp and PhBookObj.h contain the declarations and code for CPhBookObj.
  • Precompiled COM files:
    Precompiling files can reduce compilation times, resulting in faster edit, compile, link, and debug cycles. The general idea is to precompile header and implementation files that do not change and reuse the compiled code, instead of recompiling the same files for each source code module in the project. The ATL COM AppWizard automatically sets up precompiling of the standard ATL files by designating file StdAfx.cpp to be precompiled through file StdAfx.h. This produces a precompiled header file (*.pch) using the project name, for example, PhBook.pch.
    See the Visual C++ documentation for more details. They are used to build a precompiled header file PhBook.pch. Visual C++ 6.0 users will see also see file basetsd.h under External Dependencies. This file handles 64-bit wide types and values. We will not use 64-bit types in this course.

SEMrush Software