如何在C ++中使用GetProcessMemoryInfo? [英] How to use GetProcessMemoryInfo in C++?

查看:1117
本文介绍了如何在C ++中使用GetProcessMemoryInfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows 7 32上的C ++应用程序中使用 GetProcessMemoryInfo psapi.h



我按照一些教程,我做了类似的:

  PPROCESS_MEMORY_COUNTERS pMemCountr; 

pMemCountr = new PROCESS_MEMORY_COUNTERS();
bool result = GetProcessMemoryInfo(GetCurrentProcess(),
pMemCountr,
sizeof(PPROCESS_MEMORY_COUNTERS));

问题是我总是从执行 GetProcessMemoryInfo()方法。



<$ p

$ p> sizeof(PPROCESS_MEMORY_COUNTERS)

产生 PPROCESS_MEMORY_COUNTERS 这是一个 PROCESS_MEMORY_COUNTERS * 类型指针(注意在开始时注意双 P )。



你想要的是

  sizeof(PROCESS_MEMORY_COUNTERS)

此外,如果没有 new here:

  PROCESS_MEMORY_COUNTERS memCounter; 
bool result = GetProcessMemoryInfo(GetCurrentProcess(),
& memCounter,
sizeof(memCounter));


I'm trying to use the function GetProcessMemoryInfo of psapi.h inside a C++ application on Windows 7 32-bit.

I followed some tutorial and I did something like:

PPROCESS_MEMORY_COUNTERS pMemCountr;

pMemCountr = new PROCESS_MEMORY_COUNTERS();
bool result = GetProcessMemoryInfo(GetCurrentProcess(),
                                   pMemCountr,
                                   sizeof(PPROCESS_MEMORY_COUNTERS));

The problem is that i always obtain "false" from the execution of the GetProcessMemoryInfo() method. What am I doing wrong here?

解决方案

The problem is

sizeof(PPROCESS_MEMORY_COUNTERS)

yields the size of PPROCESS_MEMORY_COUNTERS which is a PROCESS_MEMORY_COUNTERS* type pointer (note double P in the beginning).

What you want is

sizeof(PROCESS_MEMORY_COUNTERS)

Also you'll be much better off without new here:

PROCESS_MEMORY_COUNTERS memCounter;
bool result = GetProcessMemoryInfo(GetCurrentProcess(),
                                   &memCounter,
                                   sizeof( memCounter ));

这篇关于如何在C ++中使用GetProcessMemoryInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆