Thread snapshot using CreateToolhelp32Snapshot is empty

I'm trying to get a snapshot of a process's thread. However, it's either returning an empty snapshot or thread_entry is not being populated. No matter what I seem to do my value th32OwnerProcessID is always 0. Any idea as to why this might be happening?

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.");
            success = Thread32Next(snapshot,&thread_entry);
        return thread_list;
} else {
    err("Could not obtain snapshot");
    return thread_list;


You should assign dwSize field of THREADENTRY32 structure to size of this structre before calling CreateToolhelp32Snapshot.

Need Your Help

Verify data, how can I make null type count as string type

php string null

I'm trying to verify data from users before inserting it into DB. I have an array of a list of fields with various field types those input data has to be.