如何在C ++中使用GetProcessMemoryInfo? [英] How to use GetProcessMemoryInfo in C++?
问题描述
我试图在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屋!