下面的一个方法,用于实现这样一个功能:获取指定进程的所有加载模块,指定进程的方式是传入进程名。
#include <Tlhelp32.h>#include <string>#include <map>#include <set> /**
* @brief : 枚举指定进程名的所有模块全路径
* @remark : 由于进程有多实例,所以注意第三个参数 bGetAllInstances 的用法
* @param[in] : pwszProcName 进程名
* @param[out] : mapExePath2ModlePaths 进程EXE全路径与其所有加载模块全路径列表,
* 所有路径都会被转成小写
* @param[in] : bGetAllInstances 指定是否将所有同名进程实例的模块都传出
* @return : 0 成功,其他为 WIN32 错误码
*/
typedef std::map<std::wstring, std::set<std::wstring>> MAP_EXE_2_MOD;
int EnumProcessModules(
/*[in]*/ LPCWSTR pwszProcName,
/*[out]*/ MAP_EXE_2_MOD& mapExePath2ModlePaths,
/*[in]*/ BOOL bGetAllInstances /*= FALSE */
)
{
if (NULL == pwszProcName)
{
return ERROR_INVALID_PARAMETER;
} // list all processes
HANDLE hSnapProc =