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

  • SEARCH
  • Home
  • 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 3317226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:33:47+00:00 2026-05-17T22:33:47+00:00

I am trying to use the Windows performance counters to get the virtual bytes

  • 0

I am trying to use the Windows performance counters to get the virtual bytes usage of a specific process. It seemed simpler to read the % CPU usage, so I thought I would try to get that to work first.

At the top of the file, I have this:

#include <pdh.h>
#include <pdhmsg.h>

Then in a function, I have this:

PDH_STATUS status = ERROR_SUCCESS;

PDH_HQUERY query = NULL;
status = PdhOpenQuery(
    NULL,
    0,
    &query);
CHECK(status == ERROR_SUCCESS, L"Couldn't create query.");

PDH_HCOUNTER counter = NULL;
status = PdhAddCounter(query, L"\\Processor(_Total)\\% Processor Time", 0, &counter);
CHECK(status == ERROR_SUCCESS, L"Couldn't add counter.");

status = PdhCollectQueryData(query);
CHECK(status == ERROR_SUCCESS, L"Couldn't collect query data.");
Sleep(2000);

status = PdhCollectQueryData(query);
CHECK(status == ERROR_SUCCESS, L"Couldn't collect query data.");
Sleep(2000);

PDH_RAW_COUNTER rawValue;
status = PdhGetRawCounterValue(&counter, NULL, &rawValue);
CHECK(status == ERROR_SUCCESS, L"Couldn't get the raw counter value.");

status = PdhCloseQuery(&query);
CHECK(status == ERROR_SUCCESS, L"Couldn't close the query handle.");

CHECK is macro that is used on the project to assert. The status is ERROR_SUCCESS at every call until the call to PdhGetRawCounterValue(). When I call that function, the result is 0xC0000BBC which is defined in pdhmsg.h as PDH_INVALID_HANDLE. The reason for the call to Sleep() is that this page says you need to read two samples for some counters and wait at least one second in between.

Am I doing something wrong?

  • 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-05-17T22:33:47+00:00Added an answer on May 17, 2026 at 10:33 pm

    I think you need to remove the ampersand (don’t take the address of counter):

    status = PdhGetRawCounterValue(counter, NULL, &rawValue);
    

    And it looks like the call to PdhCloseQuery also should probably not be passing the address of the parameter.

    status = PdhCloseQuery(query);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use c#'s performance counters to track the throughput of an application
I am trying to use Windows Workflow and have a model that looks similar
I am trying to use native windows API with Qt using mingw toolset. There
I am trying to use MinGW to compile a C program under Windows XP.
Hi I'm trying to use mono-service2 to run a stock Windows Service Project from
I'm trying to use NAnt/NAntContrib build script to build a web application on Windows
I'm trying to create a c++ library for use on windows/MSVC. My problem is
I have c# that will run in a windows service. I'm trying to use
I'm trying to write Windows app to get data from From Fox Pro DB,
I've been trying to use the Windows Authentication low level credential API functions 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.