CallNtPowerInformation(SystemPowerInfomation ...)中的数据不正确?

时间:2014-06-10 03:45:18

标签: c++ windows winapi

尝试从CallNtPowerInformation(SystemPowerInfomation ...)获取一些数据,但返回的数据似乎不正确(lidpresent应该是真的但是它是假的,VideoDimPresent应该是假的,但它是' s真的..)我是C ++的新手,我很确定我做错了什么。

我的代码:

#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;
}

1 个答案:

答案 0 :(得分:3)

您通过了SystemPowerInformation,因此预计lpOutputBuffer将指向SYSTEM_POWER_INFORMATION结构。

如果您希望SystemPowerCapabilities,则可能需要传递SystemPowerInformation而不是SYSTEM_POWER_CAPABILITIES

请参阅CallNtPowerInformation文档。