Lesson 5: Using the Dependency Walker

Visual C++ provides other utilities in addition to the debugger that can help you look inside an application or DLL module. In this lesson, you will learn how to use the Dependency Walker utility, sometimes referred to by its file name Depends.exe.

After this lesson, you will be able to:

  • Explain why Windows programs depend on other modules to run.
  • Execute the Dependency Walker utility to examine a program's dependencies.
Estimated lesson time: 15 minutes

What Is a Dependency?

A Windows program is not as self-sufficient as it might appear on the surface. Even the simplest "Hello, world" program requires the presence of several DLLs provided by the system, such as Kernel32 and GDI32. Because the elementary MyApp program (seen in examples throughout this book) links to MFC, the program depends on the help of other module files, such as MFC42.dll. In turn, MFC cannot run without other files, such as the C run-time library MSVCRT.dll. This string of required modules must all be present and available to the operat-ing system before a program can execute. Together, they form a program's dependencies.

Each executing Windows module, whether application or DLL, keeps a list of its dependencies in a header area within the executable file. When the operating system loads a module, it reads the list of dependencies and loads each required module. Only when all dependencies are loaded does the original program run.

Dependency Information

Ordinarily, a program's dependencies are invisible to users. A dependency usually makes itself known to users only when it is missing. In that case, Windows displays a message explaining that the requested program cannot run because a required file cannot be found.

The Dependency Walker utility reads the dependency list in a program's header and displays information about each dependency. The results are illustrated in Figure 13.9, which shows the dependencies for a typical program named Demo.exe.

click to view at full size.

Figure 13.9 The Dependency Walker utility

The Dependency Walker reveals such information as:

  • The name and location of each file required to run an application or DLL.
  • The base address of each dependency module.
  • Version information about each dependency module.
  • Whether each dependency module contains debug information.

  • To start the Dependency Walker
    1. On the Start menu, click Programs.
    2. Click Microsoft Visual Studio 6.0, click Microsoft Visual Studio 6.0 Tools, and then click Depends. As with any utility, you can also add a command to the Visual C++ Tools menu to invoke the Dependency Walker.
    3. When the utility appears, click Open on the File menu and browse to the application or DLL that you would like to examine.

    The Dependency Walker is an MDI application, so you can open several views, each showing the dependencies for a different executable file. As Figure 13.9 reveals, the Dependency Walker displays four panes separated by split bars. Table 13.5 describes the four panes identified in Figure 13.9.

    Table 13.5 The Four Panes Displayed in the Dependency Walker

    Pane Description
    Module dependency tree A hierarchical tree showing the program's dependencies. The tree often contains duplicate names because several modules can have the same dependencies.
    Parent import function list A list of parent import functions for the module selected in the Module dependency tree. Parent import functions are those functions (in the selected module) that are called by its parent module. The selected module must export every function that the parent is importing from it. If the selected module does not export one of the functions that the parent module expects to call, an unresolved external error occurs when the module is loaded.
    Export function list A list of functions exported by the module selected in the Module dependency tree. Export functions are functions that a module exposes to other modules.
    Module list A list of all required dependencies for the opened program. This list defines the minimum set of files needed for the program to execute.

    Lesson Summary

    This lesson introduced the Dependency Walker, a utility that provides information about the modules a Windows program requires to run. Such modules are known as dependencies. The Dependency Walker displays:

    • A tree view of modules forming a program's dependencies.
    • A list of import functions called by a module's parent.
    • A list of functions that a module exports.
    • A list of a program's dependencies.


    Microsoft Press - Desktop Applications with Microsoft Visual C++ 6. 0. MCSD Training Kit
    Desktop Applications with Microsoft Visual C++ 6.0 MCSD Training Kit
    ISBN: 0735607958
    EAN: 2147483647
    Year: 1999
    Pages: 95

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