项目需求要用到,然后找到MSDN上面的一个例子。摘录下来,方便小伙伴们用。
#include
#pragma comment(lib,"Psapi.lib")
void PrintModules( DWORD processID ) {
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
// Print the process identifier.
printf( "\nProcess ID: %u\n", processID );
// Get a list of all the modules in this process.
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess)
return;
if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ ) {
TCHAR szModName[MAX_PATH];
// Get the full path to the module's file.
if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
sizeof(szModName) / sizeof(TCHAR))) {
// Print the module name and handle value.
char msg[1024];
sprintf_s(msg,"\t%s (0x%08X)\n",szModName, hMods[i]);
OutputDebugString(msg);
}
}
}
CloseHandle( hProcess );
}
本文链接:https://it72.com/9375.htm