You are trying to return two logically different bits of information: first, "What is the list of processes?" and secondly, "Is it possible to compute a list of processes?" I suggest you return those of two variable variables:
bool get_running_proc_list(vector<DWORD>& result)
{
DWORD proc_list[1024], size;
if(!EnumProcesses(proc_list, sizeof(proc_list), &size))
{
return false;
}
result = vector<DWORD>(proc_list, proc_list + size/sizeof(DWORD));
return true;
}
But I can try to save a couple of memcpy's:
bool get_running_proc_list(vector<DWORD>& result)
{
result.clear();
result.resize(1024);
DWORD size;
if(!EnumProcesses(&result[0], result.size()*sizeof(DWORD), &size))
{
result.clear();
return false;
}
result.resize(size/sizeof(DWORD));
return true;
}
source
share