简体   繁体   中英

Incorrect Data From CallNtPowerInformation(SystemPowerInfomation…)?

Trying to get some data from CallNtPowerInformation(SystemPowerInfomation…) but the returned data doesn't seem to be correct (lidpresent should be true but it's false, VideoDimPresent should be false but it's true..) I'm new to C++ and I'm pretty sure I'm doing something wrong.

My code:

#include <NTstatus.h>
#define WIN32_NO_STATUS
#include <windows.h>
#include <Powrprof.h>
#include <iostream>
#pragma comment(lib, "Powrprof.lib")

int main()
{

   SYSTEM_POWER_CAPABILITIES spwr;
   NTSTATUS status = ::CallNtPowerInformation(SystemPowerInformation, NULL, 0, &spwr, sizeof(SYSTEM_POWER_CAPABILITIES));

    if(STATUS_SUCCESS == status){

      if(spwr.LidPresent){
        std::cout << "LidPresent TRUE!" << std::endl;
      }else{
        std::cout << "LidPresent FALSE!" << std::endl;
      }
      if(spwr.VideoDimPresent){
        std::cout << "VideoDimPresent TRUE!" << std::endl;
      }else{
        std::cout << "VideoDimPresent FALSE!" << std::endl;
      }
      if(spwr.SystemS1){
        std::cout << "SystemS1 TRUE!" << std::endl;
      }else{
        std::cout << "SystemS1 FALSE!" << std::endl;
      }
      if(spwr.SystemS2){
        std::cout << "SystemS2 TRUE!" << std::endl;
      }else{
        std::cout << "SystemS2 FALSE!" << std::endl;
      }
      if(spwr.SystemS3){
        std::cout << "SystemS3 TRUE!" << std::endl;
      }else{
        std::cout << "SystemS3 FALSE!" << std::endl;
      }
      if(spwr.SystemS4){
        std::cout << "SystemS4 TRUE!" << std::endl;
      }else{
        std::cout << "SystemS4 FALSE!" << std::endl;
      }
   }
   else
   {
      std::cout << "CallNtPowerInformation failed. Status: " << status << std::endl;
   }

   return status;
}

You passed SystemPowerInformation , so lpOutputBuffer is expected to point to SYSTEM_POWER_INFORMATION structure.

You may want to pass SystemPowerCapabilities rather than SystemPowerInformation if you expect SYSTEM_POWER_CAPABILITIES .

See CallNtPowerInformation documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM