遍歷程序使用的動態鏈接庫(dll), 首先需要遍歷所有進程, 匹配進程名稱與進程ID, 然後根據進程名稱, 輸出所有使用的庫(dll).
示例中Image.exe是預先啟動的程序. 代碼包含遍歷進程的代碼, 和輸出動態鏈接庫(dll)的代碼.
代碼:
/*
* main.cpp
*
* Created on: 2014.06.08
* Author: Spike
*/
/*vs 2012*/
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <windows.h>
#include <TlHelp32.h>
using namespace std;
bool traverseProcesses (std::map<std::string, int>& _nameID)
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE) {
std::cout << "CreateToolhelp32Snapshot Error!" << std::endl;;
return false;
}
BOOL bResult =Process32First(hProcessSnap, &pe32);
int num(0);
while(bResult)
{
std::string name = pe32.szExeFile;
int id = pe32.th32ProcessID;
//std::cout << "[" << ++num << "] : " <<"Process Name:"
//