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.
GetProcessMemoryInfotakes a process handle, not a window handle. After you find the window, you can callGetWindowThreadProcesIdto the process ID, thenOpenProcessto get a handle to the process. Then you can finally callGetProcessMemoryInfofor that handle.When you do call it, you don’t need the
BOOL WINAPIat the beginning. You normally want to assign the return value so you can check whether it succeeded, something like:Edit: here’s a really simplistic demo: