【发布时间】:2011-02-17 16:39:30
【问题描述】:
所有, 在这里需要一些帮助。我来自纯 Java 背景,对 C 编程知之甚少。基本上我需要编写一个 C 程序(并创建一个可执行文件),它将在 Windows 机器(XP/2008/7)上输出空闲字节(RAM)的数量
我对此进行了一些研究,发现有一个名为 GlobalMemoryStatusEx 的函数,还有一个链接: http://msdn.microsoft.com/en-us/library/aa366589(v=vs.85).aspx
我已经用 gcc 安装了 cygwin,而上面的程序甚至不能为我编译。我知道我在这里做了一些愚蠢的事情..
$ gcc hello.c -o hello.exe
hello.c:3:19: error: tchar.h: No such file or directory
hello.c: In function `main':
hello.c:7: error: `MEMORYSTATUSEX' undeclared (first use in this function)
hello.c:7: error: (Each undeclared identifier is reported only once
hello.c:7: error: for each function it appears in.)
hello.c:7: error: expected `;' before `statex'
hello.c:9: error: `statex' undeclared (first use in this function)
非常感谢任何帮助!
【问题讨论】:
-
即使你能掌握这个统计数据,也应该警告你它在很大程度上是无用的。
-
更新:我安装了 MiniGW,它摆脱了 tchar.h 问题,但其余错误仍然存在。使用与此链接中提到的完全相同的程序:msdn.microsoft.com/en-us/library/aa366589(v=vs.85).aspx
-
@David:这不是没用,只是不代表大多数人认为的那样。
-
@sunny 停止使用 GCC 并使用 Visual Studio。这几天其实挺好的。它甚至有一个非常好的调试器。如果您是在 Windows 上开始使用 C 或 C++,那么您将通过这种方式更快地启动和运行。
-
@Sunny:你
#include <windows.h>了吗?如果你这样做了,那么 GCC 根本不支持那个 Windows API 函数,所以你要么需要自己声明它,要么将编译器切换到真正支持 Windows API 的编译器。
标签: c windows memory-management