/////////////////////////////////////////////////////////////////////////////// // // Init.cpp // // Author: Oleg Starodumov // // /////////////////////////////////////////////////////////////////////////////// // // Description: // // This is probably the simplest possible example of using DbgHelp. // It shows how to: // * Initialize and deinitialize DbgHelp // * Load symbols for all modules of the current process // * Ask DbgHelp to produce additional troubleshooting messages // // Actions: // // * Enable debug option // * Initialize DbgHelp // * Load symbols for itself // * Deinitialize DbgHelp // // /////////////////////////////////////////////////////////////////////////////// // Include files // #include #include #include #include /////////////////////////////////////////////////////////////////////////////// // Directives // #pragma comment( lib, "dbghelp.lib" ) /////////////////////////////////////////////////////////////////////////////// // main // int _tmain( int argc, const TCHAR* argv[] ) { BOOL bRet = FALSE; // Set options DWORD Options = SymGetOptions(); // SYMOPT_DEBUG option asks DbgHelp to print additional troubleshooting // messages to debug output - use the debugger's Debug Output window // to view the messages Options |= SYMOPT_DEBUG; ::SymSetOptions( Options ); // Initialize DbgHelp and load symbols for all modules of the current process bRet = ::SymInitialize ( GetCurrentProcess(), // Process handle of the current process NULL, // No user-defined search path -> use default TRUE // Load symbols for all modules in the current process ); if( !bRet ) { _tprintf(_T("Error: SymInitialize() failed. Error code: %u \n"), ::GetLastError()); return 0; } // Deinitialize DbgHelp bRet = ::SymCleanup( GetCurrentProcess() ); if( !bRet ) { _tprintf(_T("Error: SymCleanup() failed. Error code: %u \n"), ::GetLastError()); return 0; } // Complete return 0; }