CallNtPowerInformation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HK

    CallNtPowerInformation

    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:
    CallNtPowerInfo rmation


    NTSTATUS CallNtPowerInfo rmation(
    POWER_INFORMATI ON_LEVEL InformationLeve l,
    PVOID lpInputBuffer,
    ULONG nInputBufferSiz e,
    PVOID lpOutputBuffer,
    ULONG nOutputBufferSi ze
    );


    By setting Informationleve l to SystemBatterySt ate, 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_informati on;
    SYSTEM_BATTERY_ STATE sys_bat_state;


    power_informati on = CallNtPowerInfo rmation(SystemB atteryState, NULL, 0,



    &sys_bat_sta te, sizeof(sys_bat_ state));


    printf("Battery Present: \n", sys_bat_state.B atteryPresent);
    printf("Chargin g: \n", sys_bat_state.C harging);
    printf("Dischar ging: \n", sys_bat_state.D ischarging);
    printf("Maxcapa city: \n", sys_bat_state.M axCapacity);
    printf("Remaini ngCapacity: \n", sys_bat_state.R emainingCapacit y);
    printf("Rate: \n", sys_bat_state.R ate);


    system("PAUSE") ;



    }


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

    Any ideas?


    Thanks

  • Bruno van Dooren [MVP VC++]

    #2
    Re: CallNtPowerInfo rmation

    I have to write a simple program that will retrieve information about
    the System Battery, So I was able to find this WinAPI function:
    CallNtPowerInfo rmation
    Hi.

    Use the GetSystemPowerS tatus 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 CallNtPowerInfo rmation.
    I suspect you would have gotten some clues from that.

    --

    Kind regards,
    Bruno van Dooren
    bruno_nos_pam_v an_dooren@hotma il.com
    Remove only "_nos_pam"


    Comment

    Working...