MFC教程(9)-- MFC的进程和线程(2)
2010-03-25 20:35:05 来源:WEB开发网模块信息的显示
遍历模块状态和CDynLinkLibrary列表,可以显示模块状态及其扩展模块状态的有关信息。下面,给出一个实现,它显示程序的当前模块名称、句柄和初始化的CRuntimeClass类,然后显示所有扩展模块的名称名称、句柄和初始化的CRuntimeClass类。
#ifdef _DEBUG
AFX_MODULE_STATE* pState = AfxGetModuleState();
//显示应用程序的名称和句柄
TRACE("APP %s HANDLE %x ", pState->m_lpszCurrentAppName,
pState->m_hCurrentInstanceHandle);
TCHAR szT[256];
int nClasses;
nClasses=0;
//显示CRuntimeClass类信息
AfxLockGlobals(CRIT_RUNTIMECLASSLIST);
for (CRuntimeClass* pClass = pModuleState->m_classList;
pClass != NULL;pClass = pClass->m_pNextClass)
{
nClasses++;
TRACE("CRuntimeClass: %s ",pClass->m_lpszClassName, );
}
AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
TRACE("all %d classes ", nClasses);
//遍历CDynLinkLibrary列表
AfxLockGlobals(CRIT_DYNLINKLIST);
for (CDynLinkLibrary* pDLL = pState->m_libraryList; pDLL != NULL;
pDLL = pDLL->m_pNextDLL)
{
// 得到模块名并且显示
TCHAR szName[64];
GetModuleFileName(pDLL->m_hModule, szName, sizeof(szName));
TRACE("MODULE %s HANDLE IS %x ", szName, pDLL->m_hModule);
//得到CRuntimeClass信息并显示
nClasses = 0;
for (CRuntimeClass* pClass = pDLL->m_classList;
pClass != NULL; pClass = pClass->m_pNextClass)
{
nClasses++;
TRACE("CRuntimeClass: %s ",pClass->m_lpszClassName, );
}
wsprintf(szT, _T(" Module %s has %d classes"),szName, nClasses);
}
AfxUnlockGlobals(CRIT_DYNLINKLIST);
#endif
使用MFC提供的调试函数AfxDoForAllClasses可以得到DLL模块的输出CRuntimeClass类的信息。上述实现类似于AfxDoForAllClasses函数的处理,只不过增加了模块名和模块句柄信息。
更多精彩
赞助商链接