List the loaded modules in your crash report.

29 03 2008


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 😉

Advertisements