自定义一个DLL类
class Dll
{
public:
Dll(std::wstring name, std::wstring path);
~Dll();
std::wstring getDllName(void) const;
std::wstring getDllPath(void) const;
private:
std::wstring dllName;
std::wstring dllPath;
};
获取DLL信息的函数
bool GetDllFromProcess(std::vector<Dll>& dllVec, const DWORD& processId)
{
//创建系统快照,并返回进程句柄
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
if (handle == INVALID_HANDLE_VALUE)
return false;
//枚举进程模块
MODULEENTRY32 info;
info.dwSize = sizeof(MODULEENTRY32);
Module32First(handle, &info);
while (Module32Next(handle, &info) != FALSE)
{
dllVec.emplace_back(Dll(std::wstring(info.szModule), std::wstring(info.szExePath)));
}
CloseHandle(handle);
return true;
}
参考文档
MSDN - CreateToolhelp32Snapshot
MSDN - Module32First
我是江鸟,即将迈向社会的程序猿,欢迎交流~