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 7959293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:33:02+00:00 2026-06-04T04:33:02+00:00

There was a similar thread about this here , and I tried to implement

  • 0

There was a similar thread about this here, and I tried to implement it myself. i.e. Trying to get the number of threads running in the server using c++ library.

May I know exactly what COUNTER_PATH is? (e.g. “\Process(*_)\Thread Count” in the given link)? What does it mean to make a string with that and the pid number?

The following is what I have wrote so far without really understanding anything:

#include <windows.h>
#include <pdh.h> //and suppose there're other libraries as necessary...

CONST PWSTR COUNTER_PATH = L"\Process(*)\Thread Count";

int returnNumThreads()
{
    HQUERY hQuery = NULL;
    HCOUNTER hCounter;
    DWORD counterType;
    PDH_FMT_COUNTERVALUE counterValue;
    PWSTR Paths = NULL;
    PDH_STATUS pdhStatus = PdhOpenQuery(NULL, 0, &hQuery);

    pdhStatus = PdhAddCounter(hQuery, COUNTER_PATH, 0, &hCounter);
    pdhStatus = PdhCollectQueryData(hQuery);
    pdhStatus = PdhGetFormattedCounterValue(hCounter,
                    PDH_FMT_LONG,
                    &counterType,
                    &counterValue);
    return counterValue.longValue;
}

// **Here, I removed all the error checking codes such as 
// "if (pdhStatus != ERROR_SUCCESS){...}" for better readability

**Also, the solution given in the link above says to expand the wildcard path, but when I checked the PdhAddCounter page, it said: “If the counter path contains a wildcard character, all counter names matching the wildcard character are added to the query,” so I wasn’t sure if expansion is really needed.

I’ve been looking at various examples, but I’m not still sure if I’m creating the query correctly or still what that COUNTER_PATH is. Can anybody give me an explanation?

  • 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-04T04:33:04+00:00Added an answer on June 4, 2026 at 4:33 am

    PdhAddCounter adds named counters to an open query. L"\Process(*)\Thread Count" is such a name. It’s considered a “path” name as its syntax is hierarchical (parts separated by \), similar to file paths.

    The wildcard means that you want to add the thread counters for Process(Foo), Process(Bar), etc to get the total number of threads for all processes together. (If you’re running two copie of foo.exe, the second is \Process(Foo#1)

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

Sidebar

Related Questions

This is a very serious question: I've seen lots of threads here about gravatars
I'm stumped. There are several threads out there that reference a similar problem, but
is there similar syntax to php's $$variable in python? what I am actually trying
There are similar questions to this, but I don't think anyone has asked this
There are similar questions out there on this topic, such as When can I
Is there anything similar to getElementById in actionscript? I'm trying to make a prototype
I've seen a couple similar threads to this question, but none of them really
Similar to this thread for C# , I need to split a string containing
I've seen the myriad threads sprawled across the Internet about the following similar code
Ok, I'm going nuts here. I'm trying to implement a basic popup window to

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.