Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,059 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,543 people online right now. Registration is fast and FREE... Join Now!




Battery Snippet Errors

 
Reply to this topicStart new topic

Battery Snippet Errors

JoaoPatrx
4 Aug, 2008 - 12:26 AM
Post #1

New D.I.C Head
*

Joined: 28 Jul, 2008
Posts: 2

Hi!

I'm trying to compile the code submited by dance_monkey which he named battery snippet. The original post can be found here http://www.dreamincode.net/code/snippet468.htm. I've made the same question on the original post but a few days have past and I got no answer so I decided to post it here as well.
Here are the errors I get when compiling it with gcc

battery.cpp: In function 'int main()':
battery.cpp:17: error: 'SYSTEM_POWER_STATUS' was not declared in this scope
battery.cpp:17: error: expected `;' before 'sps' battery.cpp:18: error: 'sps' was not declared in this scope battery.cpp:18: error: 'GetSystemPowerStatus' was not declared in this scope


CODE

#include <windows.h>
#include <iostream>

#define UNKNOWN         0xFFFFFFFF

using namespace std;

int main() {
        SYSTEM_POWER_STATUS status;

        GetSystemPowerStatus( &status );
        int life = status.BatteryLifePercent;
        int secs = status.BatteryLifeTime;

        cout << life << "%   ->   ";
        switch (status.BatteryFlag) {
               case 1: cout << "High";
                    break;
               case 2: cout << "Low";
                    break;
               case 4: cout << "Critical";
                    break;
               case 8: cout << "Charging";
                    break;
               case 128: cout << "No system battery";
                    break;
               case 256: cout << "Unknown status";
                    break;
        }

        if (secs == UNKNOWN) {
                cout << endl << "Amount of time remaining is unkown";
        }
        else cout << endl << secs << " seconds remaining";
        
        Sleep( 2000 );
}



Plz help me!
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Battery Snippet Errors
4 Aug, 2008 - 10:17 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
The program worked fine for me. I would imagine that the problem is probably your windows.h file and or the version of windows you are working with.

This function is only available on XP and above, so you need to ensure that you have an up to date windows header.
User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: Battery Snippet Errors
4 Aug, 2008 - 04:12 PM
Post #3

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
Make sure your MinGW installation is recent. If you're using Cygwin instead, then really make sure, as the Cygwin Windows API headers tend to lag behind the MinGW ones (although they are mostly borrowed from the MinGW project anyway). There should NOT need to be any special preprocessor definitions given to get those parts of the header (nothing like _WIN32_WINNT=0x0xxx).
User is offlineProfile CardPM
+Quote Post

JoaoPatrx
RE: Battery Snippet Errors
6 Aug, 2008 - 05:04 PM
Post #4

New D.I.C Head
*

Joined: 28 Jul, 2008
Posts: 2

QUOTE(perfectly.insane @ 4 Aug, 2008 - 05:12 PM) *

Make sure your MinGW installation is recent. If you're using Cygwin instead, then really make sure, as the Cygwin Windows API headers tend to lag behind the MinGW ones (although they are mostly borrowed from the MinGW project anyway). There should NOT need to be any special preprocessor definitions given to get those parts of the header (nothing like _WIN32_WINNT=0x0xxx).



Thanks for the advice but still isn't working on MinGW, anyway any hints on how to build this with Visual Studio 2008 for ppc? It's just paste and build while building for Win32 but building it for a mobile device seems to be a diferent story...could really use some help in this all I've ever done for Windows Mobo was Hello World and Fibo tongue.gif By the way the errors I presented above are exactly the ones I get when trying to build for ppc with VS.

battery.cpp: In function 'int main()':
battery.cpp:17: error: 'SYSTEM_POWER_STATUS' was not declared in this scope
battery.cpp:17: error: expected `;' before 'sps' battery.cpp:18: error: 'sps' was not declared in this scope battery.cpp:18: error: 'GetSystemPowerStatus' was not declared in this scope


This post has been edited by JoaoPatrx: 6 Aug, 2008 - 05:25 PM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Battery Snippet Errors
6 Aug, 2008 - 08:30 PM
Post #5

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
The file compiles fine for me in Dev-C++ 4.9.9.2 -- look at your Winbase.h and see if SYSTEM_POWER_STATUS and GetSystemPowerStatus are both declared.


I am not sure this would work for mobile devices... The version of windows that runs on mobiles is not a complete version (MUCH smaller). Not sure of that, but you may wish to check with Windows CE and Windows Mobile power management reference.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:20PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month