User forums > Using Code::Blocks

Problem compiling some windows specific functions!

(1/2) > >>

fioan89:
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);
  
}

--- End code ---

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

--- End code ---

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;
}

--- End code ---

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 ===|

--- End code ---
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

--- End code ---

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!

Ceniza:
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).

fioan89:

--- Quote from: 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).

--- End quote ---

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

Jenna:

--- Quote from: fioan89 on March 07, 2010, 07:17:45 pm ---
--- Quote from: 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).

--- End quote ---

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

--- End quote ---

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.

fioan89:
Well my compiler is mingw!And yeah i think the setting's are my problem since visual studio compile the code with succes!

Navigation

[0] Message Index

[#] Next page

Go to full version