1

I have this problem and can't get solved on this test code.

Invalid arguments Candidates are:

? GetProcessMemoryInfo(?, _PROCESS_MEMORY_COUNTERS *, ?)

How to determine CPU and memory consumption from inside a process?

I tried GetProcessMemoryInfo(GetCurrentProcess(),&info,info.cb); and GetProcessMemoryInfo(GetCurrentProcess(),(*PROCESS_MEMORY_COUNTERS)&info,info.cb); I use mingw64 version MinGW-W64-builds-4.2.0 gcc version 4.9.2 with: -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 I tried adding path and includes, added -lpaspi to the gcc++ build parameters in eclipse but nothing seems to help. any ideas?

#include <windows.h>
#include <psapi.h>

LPVOID file_version;
HANDLE handle;
PROCESS_MEMORY_COUNTERS_EX info;
MEMORYSTATUSEX memoryInfo;
DWORDLONG totalVirtualMemory;
DWORDLONG virtualMemoryUsed;
SIZE_T virtualMemoryUsedByMe;
DWORDLONG totalPhysicalMemory;
DWORDLONG physicalMemoryUsed;
SIZE_T physicalMemoryUsedByMe;

void init(){
          bool error  =  GetFileVersionInfo("psapi.lib",0,GetFileVersionInfoSize("psapi.h",0),file_version);
          info.cb = sizeof(info);
            bool okay = GetProcessMemoryInfo(GetCurrentProcess(),(*PROCESS_MEMORY_COUNTERS)&info,info.cb);                      
           memoryInfo.dwLength = sizeof(MEMORYSTATUSEX);
          GlobalMemoryStatusEx(&memoryInfo);
          totalVirtualMemory = memoryInfo.ullTotalPageFile;//Total Virtual Memory:
          virtualMemoryUsed = memoryInfo.ullTotalPageFile - memoryInfo.ullAvailPageFile;//Virtual Memory currently used:
}
double GetCurrentValue(){
     HANDLE handle = GetCurrentProcess();
     info.cb = sizeof(info);
     GetProcessMemoryInfo(handle, (PROCESS_MEMORY_COUNTERS*)&info,info.cb);
     virtualMemoryUsedByMe = info.PrivateUsage; //Virtual Memory currently used by current process:
     totalPhysicalMemory = memoryInfo.ullTotalPhys;//Total Physical Memory (RAM):
     physicalMemoryUsed = memoryInfo.ullTotalPhys - memoryInfo.ullAvailPhys;//Physical Memory currently used:
     physicalMemoryUsedByMe = info.WorkingSetSize;//Physical Memory currently used by current process:
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Andre
  • 172
  • 2
  • 8

1 Answers1

1

You are passing an uninitialized pointer (file_version). It is supposed to point to a buffer. See the MSDN documentation for how to determine the size of the buffer that is needed.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • You are probeply right, but this doesnt give a error for now. The documents say: If PSAPI_VERSION is 2 or greater, this function is defined as K32GetProcessMemoryInfo in Psapi.h http://msdn.microsoft.com/de-de/library/windows/desktop/ms683219%28v=vs.85%29.aspx – Andre Dec 22 '14 at 16:25