Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: fioan89 on March 07, 2010, 07:00:00 pm

Title: Problem compiling some windows specific functions!
Post by: fioan89 on March 07, 2010, 07:00:00 pm
Hi guy's.I'm kind a new to C:B.I have some problems compiling a function that get the free available memory.Here is my little code:
 mem_load.cpp:
Code
#include "mem_load.h"

DWORDLONG memory_load()
{
  MEMORYSTATUSEX statex;

  statex.dwLength = sizeof (statex);

  GlobalMemoryStatusEx (&statex);

  
  return (statex.ullAvailPhys/DIV);
  
}

Here's the mem_load.h:
Code
#ifndef MEM_LOAD_H_INCLUDED
#define MEM_LOAD_H_INCLUDED
#include <windows.h>

typedef struct _MEMORYSTATUSEX {
  DWORD     dwLength;
  DWORD     dwMemoryLoad;
  DWORDLONG ullTotalPhys;
  DWORDLONG ullAvailPhys;
  DWORDLONG ullTotalPageFile;
  DWORDLONG ullAvailPageFile;
  DWORDLONG ullTotalVirtual;
  DWORDLONG ullAvailVirtual;
  DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;

#define DIV 1024
DWORDLONG mem_info();

#endif // MEM_LOAD_H_INCLUDED

And again the source code for the main.cpp:
Code
#include <iostream>
#include "mem_load.h"
using namespace std;

int main()
{
    DWORDLONG meminfo=mem_info();
    cout << meminfo << endl;
    return 0;
}

Now when i try to compile this,i get this error message:
Code
C:\CodeBlocks\SystemInfo\mem_load.cpp||In function `DWORDLONG mem_info()':|
C:\CodeBlocks\SystemInfo\mem_load.cpp|9|error: `GlobalMemoryStatusEx' was not declared in this scope|
C:\CodeBlocks\SystemInfo\mem_load.cpp|9|warning: unused variable 'GlobalMemoryStatusEx'|
||=== Build finished: 1 errors, 1 warnings ===|
I must say that at the C:B menu  Settings -> compiler and debugger-->search directories->linker tab ,i add this path:
Code
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib  //for the kernel32.lib
C:\Windows\System32  //for the kernel32.dll

Please help me if you can i don't anymore know what to do,i done a lot of search with google but i couldn't find anything to help me!
Some people said that before #include <windows.h> add this:#define WINVER 0x0500 but that get  me more errors!
So please give a hand of help!
Please excuse my bad english!
Title: Re: Problem compiling some windows specific functions!
Post by: Ceniza on March 07, 2010, 07:14:34 pm
Please ask your question in a Windows programming forum. We only provide support for Code::Blocks, not for errors thrown by your compiler or any other programming question that has nothing to do with Code::Blocks itself (as in compiling Code::Blocks or extending it).
Title: Re: Problem compiling some windows specific functions!
Post by: fioan89 on March 07, 2010, 07:17:45 pm
Please ask your question in a Windows programming forum. We only provide support for Code::Blocks, not for errors thrown by your compiler or any other programming question that has nothing to do with Code::Blocks itself (as in compiling Code::Blocks or extending it).

Hm...I just compiled the same code with visual studio 2008 with no problems!Now i'm asking where is the problem?
Title: Re: Problem compiling some windows specific functions!
Post by: Jenna on March 07, 2010, 07:31:54 pm
Please ask your question in a Windows programming forum. We only provide support for Code::Blocks, not for errors thrown by your compiler or any other programming question that has nothing to do with Code::Blocks itself (as in compiling Code::Blocks or extending it).

Hm...I just compiled the same code with visual studio 2008 with no problems!Now i'm asking where is the problem?

The problem is most likely with your compiler setup, but you did not tell which one you use.

Be aware that C::B is not a compiler "just" an IDE.
So if you know which settings you need, but don't know where or how to set it, feel free to ask here, otherwise ask in a forum dedicated to general programming questions, the C::B forum is the wrong place for this kind of questions.
Title: Re: Problem compiling some windows specific functions!
Post by: fioan89 on March 07, 2010, 08:03:14 pm
Well my compiler is mingw!And yeah i think the setting's are my problem since visual studio compile the code with succes!
Title: Re: Problem compiling some windows specific functions!
Post by: stahta01 on March 07, 2010, 10:57:27 pm
Well my compiler is mingw!And yeah i think the setting's are my problem since visual studio compile the code with succes!

Turn on Full Compiler Logging and post what you think is wrong; if you have no idea what is wrong post in a group that support the source code/library/project.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F


EDIT: The use of Visual Studio Libraries (from Windows SDK; kernel32.lib ) under MinGW GCC is NOT likely to work!!!

EDIT2: MinGW GCC does support linking to DLLs that use the C Naming protocol.

EDIT3: I think you need to go to a site that supports Windows C/C++ programming and the use of the MinGW GCC Compiler.

EDIT4: After adding _WIN32_WINNT=0x0501 your code had obvious problems; I suggest asking your instructor for help if this is a class assignment; if not, I suggest going to a basic programming site that support C/C++ under Windows.

Tim S.

PS, Mingw is a group; the Compiler is GCC or MinGW GCC.