LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Battery Status

Hi,
 
I'm using the Windows SDK function GetSystemPowerStatus (LPSYSTEM_POWER_STATUS lpSystemPowerStatus) to obtain the status of a Laptop Battery.  On execution of this function I'm receiving a General Protection Fault, the reason for which, I'm not sure.
 
Can anyone help?
 
Thanks in advance.
 
(CVI 8.0.1, Windows XP SP2)
0 Kudos
Message 1 of 5
(3,672 Views)

Could you post a snippet of code showng the exact declaration and function call you are using?

JR

0 Kudos
Message 2 of 5
(3,663 Views)

JR,

Below is a snipet of the code used:

LPSYSTEM_POWER_STATUS lpSystemPowerStatus = 0;

    GetSystemPowerStatus (lpSystemPowerStatus);

Thanks,

James

0 Kudos
Message 3 of 5
(3,647 Views)
The function call is expecting a pointer, so the call should be:
 
    GetSystemPowerStatus (&lpSystemPowerStatus);
 
JR
 
Message 4 of 5
(3,641 Views)

Hi,

  you've just set a long pointer to a structure to zero, so the memory address being used is 0!!
Essentially you created a pointer and pointed it to nothing rather than to a defined memory space = GPF time!

Try this instead :

#include <cvirte.h>
#include <windows.h>
#include
<utility.h>

int main (int argc, char *argv[])
{

/* notes to show data layout of the system power status structure

 typedef struct _SYSTEM_POWER_STATUS { 
  BYTE ACLineStatus; 
  BYTE BatteryFlag; 
  BYTE BatteryLifePercent; 
  BYTE Reserved1; 
  DWORD BatteryLifeTime; 
  DWORD BatteryFullLifeTime;
 } SYSTEM_POWER_STATUS,  *LPSYSTEM_POWER_STATUS;

*/

 SYSTEM_POWER_STATUS SystemPowerStatus;

  if (InitCVIRTE (0, argv, 0) == 0)
  return -1;    /* out of memory */

    GetSystemPowerStatus (&SystemPowerStatus);

 return 0;
}

Thanks

Sacha Emery
National Instruments (UK)

// it takes almost no time to rate an answer Smiley Wink
Message 5 of 5
(3,640 Views)