473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

CallNtPowerInformation

HK
Hi all,

I have to write a simple program that will retrieve information about
the System Battery, So I was able to find this WinAPI function:
CallNtPowerInformation
NTSTATUS CallNtPowerInformation(
POWER_INFORMATION_LEVEL InformationLevel,
PVOID lpInputBuffer,
ULONG nInputBufferSize,
PVOID lpOutputBuffer,
ULONG nOutputBufferSize
);
By setting Informationlevel to SystemBatteryState, The lpOutputBuffer
buffer receives a SYSTEM_BATTERY_STATE structure containing information

about the current system battery.
I was to compile the program and link it successfully; however when i
output all the members of the SYSTEM_BATTERY_STATE structure I am not
getting anything. Here is
the code:
#include <windows.h>
#include <powrprof.h>
#include <WinDef.h>
void main()
{
NTSTATUS power_information;
SYSTEM_BATTERY_STATE sys_bat_state;
power_information = CallNtPowerInformation(SystemBatteryState, NULL, 0,

&sys_bat_state, sizeof(sys_bat_state));
printf("BatteryPresent: \n", sys_bat_state.BatteryPresent);
printf("Charging: \n", sys_bat_state.Charging);
printf("Discharging: \n", sys_bat_state.Discharging);
printf("Maxcapacity: \n", sys_bat_state.MaxCapacity);
printf("RemainingCapacity: \n", sys_bat_state.RemainingCapacity);
printf("Rate: \n", sys_bat_state.Rate);
system("PAUSE");

}
I did add the libpowrprof.a already and the program is linking
successfully.

Any ideas?
Thanks

Oct 13 '06 #1
1 3204
I have to write a simple program that will retrieve information about
the System Battery, So I was able to find this WinAPI function:
CallNtPowerInformation
Hi.

Use the GetSystemPowerStatus function instead. It will retrieve all power
information directly into a structure.
It is very easy to use.
Btw, you did not check the return value of CallNtPowerInformation.
I suspect you would have gotten some clues from that.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Oct 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pauld avid | last post by:
I need to be know when the display goes into "suspend." It seems there is no accurate way to query the state of the monitor so I am left with trying to track the idleness of the system and compare...
4
by: naveenadevi | last post by:
Hi, I'm trying to use some power management features with windowsx xp and I have visual studio .net 2003 installed. As per documentation of ACPI, you can use the power options by including...
4
by: HK | last post by:
I need to wirte a program that will display the degration of a battery as it's nature of reducing its effective capacity during continous charging and discharging cycles. I looked at Microsoft...
0
by: faezbhanji | last post by:
I'm trying to implement the SYSTEM_POWER_POLICY structure in C#, but its a structure containing other structures and I'm not sure how to do it. I need to use the callntpowerinformation function in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.