GlobalMemoryStatusEx(),API函数的使用问题。

mscont 2011-04-09 05:43:12
#if (_WIN32_WINNT >= 0x0500)
WINBASEAPI BOOL WINAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX);
#endif

#ifndef WINVER
#define WINVER 0x0400
/*
* If you need Win32 API features newer the Win95 and WinNT then you must
* define WINVER before including windows.h or any other method of including
* the windef.h header.
*/
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT WINVER
/*
* There may be the need to define _WIN32_WINNT to a value different from
* the value of WINVER. I don't have any example of why you would do that.
* However, if you must then define _WIN32_WINNT to the value required before
* including windows.h or any other method of including the windef.h header.
*/
#endif

这里我有点不明白了,它的意思是在windows.h前面#define _WIN32_WINNT吧?
那它内部又定义成WINVER,这个WINVER又需要#define WINVER了?WINVER就是0x0400?

(_WIN32_WINNT >= 0x0500)这不就不成立了吗?

是不是要把它的值改成0x0500?!

...全文
184 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mscont 2011-04-11
  • 打赏
  • 举报
回复
楼上答非所问呀。

我在windef.h中修改#define _WIN32_WINNT WINVER为 #define _WIN32_WINNT 0x0500函数就可以用了。

另外GlobalMemoryStatusEx函数跟GlobalMemoryStatus函数使用上不同的地方,
Ex的需要先给定这个函数所使用的结构体的大小,也就是先给它的dwLength成员赋值。专业术语咋说来着?
缓存区?GlobalMemoryStatus这个函数居然可以不用给,在用Ex的时候我也没给。导致数据显示的值不
正确了(应该都是填充值吧)。记得在其他语言上用过一些API需要给定它的缓存区。估计这个函数也一样
了。去查了下这个函数的一些例子,果然如此。原来这个函数是《windows核心编程》里面的啊。

另外输出的时候得用%I64d格式。



jixingzhong 2011-04-10
  • 打赏
  • 举报
回复
预处理是有先后顺序的,(_WIN32_WINNT >= 0x0500)在前,#define WINVER 0x0400在后。
lengxujun 2011-04-09
  • 打赏
  • 举报
回复
灌水的来了,灌水又走了.

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧