Memory Error

Why does this:
1
2
3
4
5
6
7
8
9
            MEMORYSTATUSEX statex;

            statex.dwLength = sizeof (statex);

            GlobalMemoryStatusEx (&statex);

            std::string memory_load = "There is " + statex.dwMemoryLoad + "percent of memory in use.";

            TextOut(hdc, 0, 140, memory_load.c_str(), memory_load.size());

Throw an error like this

C:\Users\Joyel\Desktop\Personal Files\cpp_projects\Computer Information Display\main.cpp||In function 'LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':|
C:\Users\Joyel\Desktop\Personal Files\cpp_projects\Computer Information Display\main.cpp|40|error: 'MEMORYSTATUSEX' was not declared in this scope|
C:\Users\Joyel\Desktop\Personal Files\cpp_projects\Computer Information Display\main.cpp|40|error: expected ';' before 'statex'|
C:\Users\Joyel\Desktop\Personal Files\cpp_projects\Computer Information Display\main.cpp|42|error: 'statex' was not declared in this scope|
C:\Users\Joyel\Desktop\Personal Files\cpp_projects\Computer Information Display\main.cpp|44|error: 'GlobalMemoryStatusEx' was not declared in this scope|
||=== Build finished: 4 errors, 0 warnings ===|


Yes, I did include the windows header file.
Thanks again.
Last edited on
MEMORYSTATUSEX is actually declared in winbase.h which should be included by windows.h but there is no guarentee. Try explicitly including "winbase.h".
Is there a way I can set my compiler/IDE to include that with windows.h?

I am using Codebase.
Also it gives me the same error even when I specifically include that.
If you really, really wanted to, you could edit the windows.h file manually. It wouldn't harm anything to make sure it includes winbase.h, and if it does blame Microsoft ;)

businessman332211 wrote:
I accidentally reported LB's last post by accident, and wanted to let an admin know that it wasn't intentional.
Uh, ok, haha...
Last edited on
OK I opened the windows header file.
I see this in there,
 
#include <winbase.h> 


So that header file is already being included with windows....
So I have no idea why it's throwing that error. I am using practically the same example listed at the other site.

Also what is stdio or something header..I see that in a lot of the examples..but I never use it, should I be?
Who is an admin for this site also? I accidentally reported LB's last post by accident, and wanted to let an admin know that it wasn't intentional.
I have no idea. I have seen some complaints online about Codeblocks only..it seems that this code here: http://msdn.microsoft.com/en-us/library/aa366589(v=vs.85).aspx can be compiled in certain ones...but not using CodeBlocks with Ming..I am not entirely sure why this isn't working.
Strange.
Note that this function is available beginning with windows 200, so you should add this lines before including windows.h if you use MinGW crap which is good for windows 95:
1
2
#define WIN32_WINNt 0x0500
#define WINVER 0x0500 
OK, then I want to avoid Ming. What do I need to install then? I do not want to have to doctor my files to work arond a specific compiler. Can you give me advice for a good compiler that I should be using? Which one I mean.
If MIng is not a good one, then cdo you have any decent recommendations, I will switch instantly. Thanks.
No...actually I am using GNU GCC Compiler.

Which one should I be using?
The problem is not with the compiler, it is the outdated windows headers. If you want to develop only in windows platform, I highly recommend Visual Studio IDE/compiler. GNU GCC is very good also, but requires to be familiarized with windows headers (some of them are missing) and different macros that is needed (Visual Studio do all job for you).

I know but I prefer code::blocks. I tried Visual C++ before and I really didn't like it..partially for a variety of reasons. I am not sure what all you mean. About outdated windows headers, and other stuff. I do not want to only develop on a windows platform. I intend to do a lot of C++ and windows development, but other stuff as well. I generally find Codeblocks gives me more freedom.

The two things I don't understand though..is why would the IDE have anything to do with the speciifc issue I am having. It has to either be something I am not familiar with, or the compiler I am using, or perhaps other compiler settings issues (maybe I don't know how to configure it or something. I will go ahead and try those two defines, I just don't understand why they are needed.
If anyone else has any feedback on it I would appreciate it.
Topic archived. No new replies allowed.