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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:19:15+00:00 2026-05-19T17:19:15+00:00

I need to get the up to date memory useage of a program that

  • 0

I need to get the up to date memory useage of a program that is running. i googled it and found GetProcessMemoryInfo this looks like what i needed but i can’t get it to work.
It wont take the handle i find for the window and i am not really sure what they want.

#include <iostream>
#include <Windows.h>
#include <tchar.h> 
#include <Psapi.h>

using namespace std;


int main()
{

HANDLE hwnd = FindWindow(NULL,TEXT("Calculator"));


PPROCESS_MEMORY_COUNTERS ppsmemCounters;

DWORD cb;

BOOL WINAPI GetProcessMemoryInfo(hwnd, ppsmemCounters, cb);

return 0;
}

I am just trying to find the window’s calculator for now.
One of the errors i get is Error:a value of type “HANDLE” cannot be used to initialize an entity type “BOOL”.
Another is “error C2078: too many initializers”.
I am using VC++ 2010, and my os is Windows 7.

  • 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-19T17:19:15+00:00Added an answer on May 19, 2026 at 5:19 pm

    GetProcessMemoryInfo takes a process handle, not a window handle. After you find the window, you can call GetWindowThreadProcesId to the process ID, then OpenProcess to get a handle to the process. Then you can finally call GetProcessMemoryInfo for that handle.

    When you do call it, you don’t need the BOOL WINAPI at the beginning. You normally want to assign the return value so you can check whether it succeeded, something like:

    bool succeded = GetProcessMemoryInfo(process, /* ... */);
    

    Edit: here’s a really simplistic demo:

    #include <windows.h>
    #include <psapi.h>
    #include <iostream>
    
    int main(int argc, char **argv) {
        HWND window = FindWindow(NULL, argv[1]);
        DWORD id;
        GetWindowThreadProcessId(window, &id);
    
        HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, id);
    
        PROCESS_MEMORY_COUNTERS info = {0};
        info.cb = sizeof(info);
        GetProcessMemoryInfo(process, &info, sizeof(info));
    
        std::cout << info.WorkingSetSize;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this question , if I need to get date included in the output,
I need the get a date object that specifies the next 2:00am that will
I am using this code to get previous date but i would like to
I need to get the date from the server in mm/dd/yyyy without any javascript
Question: I need to get the DATE ONLY (= date WITHOUT time) with an
Possible Duplicate: How to get current date in JavaScript I need to get todays
I need to get real world date and time in Java. I use: Date
I need to get the last day of the month given as a date
I need to get lots of data (file select , text, date ,...) from
I am using the Date Range Picker (http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/) plugin and need to get the

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.