Posts tagged modules

How to identify the module load order?

0


When an application starts, windows loads the necessary dll files to the system memory – “in required order”. But how to get the dll load order of perticular application? You’ve already seen – When we start the application via debugger, it will output the module load order info to the watch window. Have a look at it,

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\dbghelp.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\mfc42.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\user32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\gdi32.dll', no matching symbolic information found.

Seems Good! But, is there any easy method?


Yes! Take menu item, Debug -> Modules. And it will show the dialog of all loaded modules. By default the modules are sorted in load order. See the screenshot.


Now you don’t need to jump into that watch window for searching the module load order. ;)


Targeted Audience – Beginners.

List the loaded modules in your crash report.

1


In crash reports, usually we see a list of loaded modules. While writing Error Handler frameworks, for dumping crash reports we too need to get list of loaded modules which will make the debugging tasks easier. But how can we find out the loaded modules? You can use EnumerateLoadedModules() function to enumerate the loaded modules.


You can use EnumerateLoadedModules() function to enumerate the loaded modules. For calling EnumerateLoadedModules() we need provided a callback function pointer. The EnumerateLoadedModules() will send the loaded module information as callback to that provided function. Please see the following code

#include <Dbghelp.h>

// Callback function.
BOOL CALLBACK EnumerateLoadedModulesProc( PSTR ModuleName,
                                          ULONG ModuleBase,
                                          ULONG ModuleSize,
                                          PVOID UserContext )
{
    // Print the module name.
    cout << ModuleName << endl;
    return TRUE;
}

int main(int argc, char* argv[])
{
    // Enumerate loaded modules.
    EnumerateLoadedModules(
       GetCurrentProcess(),	// Process Handle
       // Callback function pointer
       (PENUMLOADED_MODULES_CALLBACK) EnumerateLoadedModulesProc,
       0 );	// User context.

       return 0;
}

Add beauty and complexity to your crash report by listing out the module names ;)

Go to Top