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:Estimated lesson time: 15 minutes
- Explain why Windows programs depend on other modules to run.
- Execute the Dependency Walker utility to examine a program's dependencies.
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.
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.
Figure 13.9 The Dependency Walker utility
The Dependency Walker reveals such information as:
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. |
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: