我想做一个like函数,它的参数是进程名的stdvector::<std::string>和.dll的std::vector<std::string>,以便在它们中找到并将其提供给一个函数,并获得匹配名称的任何内容的PROCESSENTRY32信息std::vector<PROCESSENTRY32>返回。
你可以在谷歌上搜索,但不会找到太多,因为我感谢你帮助winapi新手,但不是为了弄清楚事情
发布于 2013-05-27 16:31:56
有一个完美的例子可以完全按照你想要的on MSDN here来做。下面复制了相关代码。正如示例的介绍所说的那样
若要确定哪些进程加载了特定的DLL,必须枚举每个进程的模块。下面的示例代码使用
EnumProcessModules函数枚举系统中当前进程的模块。
下面是示例代码
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <psapi.h>
// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1
int 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 handle to the process.
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess)
return 1;
// Get a list of all the modules in this process.
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.
_tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
}
}
}
// Release the handle to the process.
CloseHandle( hProcess );
return 0;
}
int main( void )
{
DWORD aProcesses[1024];
DWORD cbNeeded;
DWORD cProcesses;
unsigned int i;
// Get the list of process identifiers.
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return 1;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the names of the modules for each process.
for ( i = 0; i < cProcesses; i++ )
{
PrintModules( aProcesses[i] );
}
return 0;
}您需要做的惟一更改是预先将感兴趣的模块名称push-back到您的std::vector<std::string>中,然后使用枚举的模块名称搜索该向量,而不是打印它们。
https://stackoverflow.com/questions/16768329
复制相似问题