Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:42:52+00:00 2026-06-16T07:42:52+00:00

I am looking to return an array of all current running process ID’s from

  • 0

I am looking to return an array of all current running process ID’s from a function using C++.

I am enumerating the list with the following function:

DWORD* xEnumProcs(){
    PROCESSENTRY32 pe32;
    HANDLE snapshot = NULL;
    DWORD pid[1024];
    DWORD* pointer;
    pointer = pid;
    int I = 0;

    snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (snapshot != INVALID_HANDLE_VALUE) {
        pe32.dwSize = sizeof(PROCESSENTRY32);
        if (Process32First(snapshot, &pe32)) {
            do {
                pid[I] = pe32.th32ProcessID;
                I++;
            } while (Process32Next(snapshot, &pe32));
        }

        CloseHandle(snapshot);

    }

    return pointer;

}

I am unsure if this is done properly. I am trying to utilize this array inside of another function like so:

void HandleProcs(){
    DWORD* xNewProcs = xEnumProcs;
}

And this is the error I am receiving on the one line in the body of the last function:

'initializing' : cannot convert from 'DWORD *(__cdecl *)(void)' to 'DWORD *'
1>          There is no context in which this conversion is possible
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:42:53+00:00Added an answer on June 16, 2026 at 7:42 am

    I think you already got your answer, but for the sake of learning, compare the C version here:

    #include <stdio.h>  // printf
    #include <Windows.h>
    #include <Tlhelp32.h>
    
    DWORD *EnumProcs(size_t *n)
    {
        DWORD *pids = NULL;
        HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        *n = 0;
        if (snapshot != INVALID_HANDLE_VALUE)
        {
            PROCESSENTRY32 pe32 = { sizeof(pe32) };
            if (Process32First(snapshot, &pe32))
            {
                do { ++*n; } while (Process32Next(snapshot, &pe32));
                pids = calloc(*n, sizeof(pe32.th32ProcessID));
                *n = 0;
                Process32First(snapshot, &pe32);  // Maybe check return value
                do { pids[(*n)++] = pe32.th32ProcessID; }
                while (Process32Next(snapshot, &pe32));
            }
            CloseHandle(snapshot);
        }
        return pids;
    }
    int main()
    {
        size_t i, n;
        DWORD *pids = EnumProcs(&n);
        for (i = 0; i < n; i++)
        { printf("%u\n", pids[i]); }
        free(pids);
    }
    

    with the C++ version:

    #include <iostream>  // std::cout
    #include <vector>  // std::vector, like List<T> in C# (or ArrayList<T> in Java)
    #include <Windows.h>
    #include <Tlhelp32.h>
    
    std::vector<DWORD> EnumProcs()
    {
        std::vector<DWORD> pids;
        HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        if (snapshot != INVALID_HANDLE_VALUE)
        {
            PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
            if (Process32First(snapshot, &pe32))
            {
                do
                {
                    pids.push_back(pe32.th32ProcessID);
                } while (Process32Next(snapshot, &pe32));
            }
            CloseHandle(snapshot);
        }
        return pids;
    }
    int main()
    {
        std::vector<DWORD> pids = EnumProcs();
        for (size_t i = 0; i < pids.size(); i++)
        { std::cout << pids[i] << std::endl; }
    }
    

    Notice how the C++ version is completely different — and doesn’t use pointers.

    Try to learn one of the two languages well before moving on to the other one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to return a PDF from a webservice call. (ATM, a custom
I have an ajax question for you all. I want to return an array
I am making a PHP function to return an array of a mysql database's
I have a result array that comes back from CodeIgniter looking like this: Array
I'm interested in speed, not good looking code, that is why I'm using array
I've just saw an unfamiliar syntax while looking for GroupBy return type: public interface
I was just looking at this code and i don't understand what RETURN TRUE
I'm looking for a way to query a SQL database with Java and return
I'm looking for an implementation of java.util.Map that has a method that will return
I'm looking for a way to atomically increment a short, and then return that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.