我正在尝试获取进程线程的快照。但是,它要么返回空快照,要么没有填充thread_entry。无论我似乎做什么,我的价值th32OwnerProcessID总是0.任何想法为什么会发生这种情况?
stack<DWORD> enumerate_threads(){
THREADENTRY32 thread_entry;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,proc_info_1.process_ID);
if(snapshot != INVALID_HANDLE_VALUE){
thread_entry.dwSize = sizeof(thread_entry);
bool success = Thread32First(snapshot,&thread_entry);
while(success == true){
msg("Got thread snapshot");
if(thread_entry.th32OwnerProcessID == proc_info_1.process_ID){
msg("Adding thread to list.");
thread_list.push(thread_entry.th32ThreadID);
success = Thread32Next(snapshot,&thread_entry);
}
CloseHandle(snapshot);
return thread_list;
}
} else {
err("Could not obtain snapshot");
return thread_list;
}
}
答案 0 :(得分:0)
在调用dwSize
之前,您应该将THREADENTRY32
CreateToolhelp32Snapshot
结构字段指定为此结构的大小。