GlobalMemoryStatus获取内存使用情况只适用于内存小于2G的机器,我机器的内存是3G,获取的总物理内存和可用内存数据都是2G。逼不得已只能尝试使用GlobalMemoryStatusEx函数,其为Kernel32.dll提供的接口,Kernel32.dll在程序启动时就已经加载进来了,但是直接使用会报错,“无法识别”,最终只能尝试以下方法:typedef BOOL (CALLBACK* GLOBALMEMORYSTATUSEX)(MEMORYSTATUS* pMemStatus);
GLOBALMEMORYSTATUSEX pGlobalMemoryStatusEx;pGlobalMemoryStatusEx = (GLOBALMEMORYSTATUSEX)GetProcAddress(GetModuleHandle(_T("Kernel32.dll")), ("GlobalMemoryStatusEx"));
if (pGlobalMemoryStatusEx)
{
MEMORYSTATUSEX MemStatEx;
MemStatEx.dwLength = sizeof(MEMORYSTATUSEX);
pGlobalMemoryStatusEx(&MemStatEx);
dwError = GetLastError();
}函数GlobalMemoryStatusEx是可以使用了,但还是有问题,MEMORYSTATUSEX又是无法识别的了,实在不知道怎么办了,请有经验的帮帮忙,谢谢了!有其他的办法也行,只要让我能正确获得大于2G机器的内存情况就可以,貌似这些函数的使用,NT系统与其他系统还不一样,不管这么多了,只要能正确获取就行。
GLOBALMEMORYSTATUSEX pGlobalMemoryStatusEx;pGlobalMemoryStatusEx = (GLOBALMEMORYSTATUSEX)GetProcAddress(GetModuleHandle(_T("Kernel32.dll")), ("GlobalMemoryStatusEx"));
if (pGlobalMemoryStatusEx)
{
MEMORYSTATUSEX MemStatEx;
MemStatEx.dwLength = sizeof(MEMORYSTATUSEX);
pGlobalMemoryStatusEx(&MemStatEx);
dwError = GetLastError();
}函数GlobalMemoryStatusEx是可以使用了,但还是有问题,MEMORYSTATUSEX又是无法识别的了,实在不知道怎么办了,请有经验的帮帮忙,谢谢了!有其他的办法也行,只要让我能正确获得大于2G机器的内存情况就可以,貌似这些函数的使用,NT系统与其他系统还不一样,不管这么多了,只要能正确获取就行。
解决方案 »
- 动态库内存泄露问题
- 为什么线程的句柄可以作为事件句柄接收信号?完成端口WSAWaitForMultipleEvents
- 多线程出现错误
- 如何获取屏幕的某个区域并将其存成内存中的位图对象?
- 调查::如果有一个微软的非官方网站,你最希望看到的内容是?
- 关于vc++.net2003智能感知的问题
- 怎么从网站上下载一个指定的文件(80端口,HTTP协议),用SDK实现
- 谷歌地图调用求助
- 如何根据屏幕得分辨率自动改变CDialog类对象的得大小?
- 用VS怎么做个基于GPS的地图创建
- CStdioFile文件 删除最后一个元素
- 写了一个tcp通信的服务器端,还没写客户端,老是出错 error C2065: 'sListen' : undeclared identifier
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;详见http://msdn.microsoft.com/en-us/library/aa366770%28VS.85%29.aspx
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
你既然连函数都没找到 其结构体肯定也没有 楼主应该用的低版本的VS,建议用高版本的。。
还有 楼主如果没有的话 可以 去MSDN在线帮助文档上面看这个函数 这个函数有微软的示例// Sample output:
// There is 51 percent of memory in use.
// There are 2029968 total Kbytes of physical memory.
// There are 987388 free Kbytes of physical memory.
// There are 3884620 total Kbytes of paging file.
// There are 2799776 free Kbytes of paging file.
// There are 2097024 total Kbytes of virtual memory.
// There are 2084876 free Kbytes of virtual memory.
// There are 0 free Kbytes of extended memory.#include <windows.h>
#include <stdio.h>// Use to convert bytes to KB
#define DIV 1024// Specify the width of the field in which to print the numbers.
// The asterisk in the format specifier "%*I64d" takes an integer
// argument and uses it to pad and right justify the number.
#define WIDTH 7void main(int argc, char *argv[])
{
MEMORYSTATUSEX statex; statex.dwLength = sizeof (statex); GlobalMemoryStatusEx (&statex); printf ("There is %*ld percent of memory in use.\n",
WIDTH, statex.dwMemoryLoad);
printf ("There are %*I64d total Kbytes of physical memory.\n",
WIDTH, statex.ullTotalPhys/DIV);
printf ("There are %*I64d free Kbytes of physical memory.\n",
WIDTH, statex.ullAvailPhys/DIV);
printf ("There are %*I64d total Kbytes of paging file.\n",
WIDTH, statex.ullTotalPageFile/DIV);
printf ("There are %*I64d free Kbytes of paging file.\n",
WIDTH, statex.ullAvailPageFile/DIV);
printf ("There are %*I64d total Kbytes of virtual memory.\n",
WIDTH, statex.ullTotalVirtual/DIV);
printf ("There are %*I64d free Kbytes of virtual memory.\n",
WIDTH, statex.ullAvailVirtual/DIV); // Show the amount of extended memory available. printf ("There are %*I64d free Kbytes of extended memory.\n",
WIDTH, statex.ullAvailExtendedVirtual/DIV);
}
这句编译提示有错误,'int (struct _MEMORYSTATUS *)' : cannot convert parameter 1 from 'struct _MEMORYSTATUSEX *' to 'struct _MEMORYSTATUS *'不知道是个什么情况,貌似还要将Ex的结构体转化为普通的?
MemStat.dwLength = sizeof(MEMORYSTATUS);
pGlobalMemoryStatusEx(&MemStat);用这个编译不会提示错误,但GetLastError的错误码是提示参数不正确,而用自定义的MEMORYSTATUSEX又会出现上面参数不能转化的错误,难道是pGlobalMemoryStatusEx = (GLOBALMEMORYSTATUSEX)GetProcAddress(GetModuleHandle(_T("Kernel32.dll")), ("GlobalMemoryStatusEx"));
获取的指针有问题?这到底是个什么问题,求解!
对于GlobalMemoryStatusEx 函数应当使用MEMORYSTATUSEX 参数,两个函数的参数是不一样的。MEMORYSTATUS statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatus (&statex);
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
这个是windows中 任务管理器中——》性能选项卡——》核心内存(中的分页数与未分页数)