Results 1 to 4 of 4

Thread: Problem with #include "windows.h"

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Unhappy Problem with #include "windows.h"

    I'm not sure if that would be a Qt programming question, but anyway.

    I want to create a software in Qt that do some things regarding process in Windows (see http://www.qtcentre.org/threads/4964...ocess?p=222983). I'm using Windows API functions to do what I want, at least for the moment.

    Now I'ld like to receive some data regarding the RAM memory consumption of a given process, what is taught how to do it here: http://stackoverflow.com/questions/6...side-a-process

    In a first moment I tried this codes in Borland C++ Builder; it worked fine.

    But when I ctr+c + ctrl+v the API code in Qt, I got some errors; essentially it seems that Qt is not recognizing the presence of the #include "windows.h", so it's not being able to recognize the variables the code needs to work.


    Code:
    Qt Code:
    1. #include "windows.h"
    2.  
    3. /.../
    4. /.../
    5.  
    6. MEMORYSTATUSEX memInfo;
    7. memInfo.dwLength = sizeof(MEMORYSTATUSEX);
    8. GlobalMemoryStatusEx(&memInfo);
    To copy to clipboard, switch view to plain text mode 

    Errors:
    15:20:27: Running build steps for project WD...
    15:20:27: Configuration unchanged, skipping qmake step.
    15:20:27: Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
    C:/QtSDK/mingw/bin/mingw32-make.exe -f Makefile.Debug
    mingw32-make.exe[1]: Entering directory `C:/Users/Endrigo/Desktop/Central350/trunk/central BD novo -v18.2.2/WD'
    g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\QtSDK\Desktop\Qt\4.8.0\mingw\include\QtCor e" -I"c:\QtSDK\Desktop\Qt\4.8.0\mingw\include\QtGui " -I"c:\QtSDK\Desktop\Qt\4.8.0\mingw\include" -I"c:\QtSDK\Desktop\Qt\4.8.0\mingw\include\ActiveQt " -I"debug" -I"." -I"c:\QtSDK\Desktop\Qt\4.8.0\mingw\mkspecs\win32-g++" -o debug\main.o main.cpp
    main.cpp: In function 'int qMain(int, char**)':
    main.cpp:28: error: 'MEMORYSTATUSEX' was not declared in this scope
    main.cpp:28: error: expected ';' before 'memInfo'
    main.cpp:29: error: 'memInfo' was not declared in this scope
    main.cpp:30: error: 'GlobalMemoryStatusEx' was not declared in this scope
    main.cpp:39: error: 'ui' was not declared in this scope
    mingw32-make.exe[1]: Leaving directory `C:/Users/Endrigo/Desktop/Central350/trunk/central BD novo -v18.2.2/WD'
    mingw32-make.exe[1]: *** [debug/main.o] Error 1
    mingw32-make.exe: *** [debug] Error 2
    15:20:29: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project WD (target: Desktop)
    When executing build step 'Make'

    Thanks,


    Momergil
    Last edited by Momergil; 28th June 2012 at 20:56.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem with #include "windows.h"

    Could be that your compiler has been configured to support an old Windows version which didn't have MEMORYSTATUSEX. See
    http://old.nabble.com/Compiling-a-C-...d30060037.html

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem with #include "windows.h"

    From the MinGW windef.h:
    Qt Code:
    1. #ifndef WINVER
    2. #define WINVER 0x0400
    3. /*
    4.  * If you need Win32 API features newer the Win95 and WinNT then you must
    5.  * define WINVER before including windows.h or any other method of including
    6.  * the windef.h header.
    7.  */
    8. #endif
    9. #ifndef _WIN32_WINNT
    10. #define _WIN32_WINNT WINVER
    To copy to clipboard, switch view to plain text mode 
    and from the header that defines MEMORYSTATUSEX:
    Qt Code:
    1. #if (_WIN32_WINNT >= 0x0500)
    2. typedef struct _MEMORYSTATUSEX {
    3. ...
    To copy to clipboard, switch view to plain text mode 

    So, in your code:
    Qt Code:
    1. #define WINVER 0x0500
    2. #include <windows.h>
    3. ...
    To copy to clipboard, switch view to plain text mode 

    Microsoft's headers work the same way, it is just that they always default you to the latest API version (in order to drive upgrades by making software backward incompatible by default).

  4. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with #include "windows.h"

    Thanks! The #define worked!


    (I would have never imagined that answer >.<)

Similar Threads

  1. Replies: 1
    Last Post: 28th April 2012, 03:53
  2. Replies: 1
    Last Post: 5th February 2011, 21:14
  3. Replies: 4
    Last Post: 10th November 2009, 19:48
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.