Winapi GetPwrCapabilities在某些计算机上给我错误的睡眠状态结果。我怎样才能得到更准确的结果?

Winapi GetPwrCapabilities在某些计算机上给我错误的睡眠状态结果。我怎样才能得到更准确的结果?,winapi,windows-7,power-management,hibernation,Winapi,Windows 7,Power Management,Hibernation,我有一台64位Win7 Ultimate机器,我在上面调用GetPwrCapabilities。但是,它告诉我睡眠状态4(休眠)不可用,并且没有休眠文件。我可以使机器休眠,并且有一个休眠文件。我做错什么了吗?还有什么我可以打电话获得准确的支持睡眠状态吗 谢谢 编辑 有趣的是,powercfg-AvailableEstates提供了正确的信息。有人知道它调用什么API或者为什么会有差异吗 添加代码 using System; using System.Collections.Generic; us

我有一台64位Win7 Ultimate机器,我在上面调用GetPwrCapabilities。但是,它告诉我睡眠状态4(休眠)不可用,并且没有休眠文件。我可以使机器休眠,并且有一个休眠文件。我做错什么了吗?还有什么我可以打电话获得准确的支持睡眠状态吗

谢谢

编辑 有趣的是,powercfg-AvailableEstates提供了正确的信息。有人知道它调用什么API或者为什么会有差异吗

添加代码

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.IO;
using System.Diagnostics;

class Program
{
    [DllImport("PowrProf.dll")]
    public static extern bool GetPwrCapabilities(out SYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities);

    static void Main(string[] args)
    {
        SYSTEM_POWER_CAPABILITIES spc;
        bool well = GetPwrCapabilities(out spc);

        Stream stdOut = System.Console.OpenStandardOutput();
        XmlSerializer x = new XmlSerializer(typeof(SYSTEM_POWER_CAPABILITIES));
        x.Serialize(stdOut, spc);
    }
}

[Serializable]
public struct SYSTEM_POWER_CAPABILITIES
{
    public bool PowerButtonPresent;
    public bool SleepButtonPresent;
    public bool LidPresent;
    public bool SystemS1;
    public bool SystemS2;
    public bool SystemS3;
    public bool SystemS4;
    public bool SystemS5;
    public bool HiberFilePresent;
    public bool FullWake;
    public bool VideoDimPresent;
    public bool ApmPresent;
    public bool UpsPresent;
    public bool ThermalControl;
    public bool ProcessorThrottle;
    public byte ProcessorMinThrottle;
    public byte ProcessorMaxThrottle;
    public bool FastSystemS4;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
    public byte[] spare2;
    public bool DiskSpinDown;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    public byte[] spare3;
    public bool SystemBatteriesPresent;
    public bool BatteriesAreShortTerm;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
    public BATTERY_REPORTING_SCALE[] BatteryScale;
    public SYSTEM_POWER_STATE AcOnLineWake;
    public SYSTEM_POWER_STATE SoftLidWake;
    public SYSTEM_POWER_STATE RtcWake;
    public SYSTEM_POWER_STATE MinDeviceWakeState;
    public SYSTEM_POWER_STATE DefaultLowLatencyWake;
}
public struct BATTERY_REPORTING_SCALE
{
    public UInt32 Granularity;
    public UInt32 Capacity;
}
public enum SYSTEM_POWER_STATE
{
    PowerSystemUnspecified = 0,
    PowerSystemWorking = 1,
    PowerSystemSleeping1 = 2,
    PowerSystemSleeping2 = 3,
    PowerSystemSleeping3 = 4,
    PowerSystemHibernate = 5,
    PowerSystemShutdown = 6,
    PowerSystemMaximum = 7
}

bool被编组为4字节。这与Win32 BOOL匹配。但是Win32 BOOLEAN是一个字节,所以您需要用
[MarshalAs(UnmanagedType.I1)]
标记所有系统\u POWER\u功能bool成员

您能给我们看一下您的代码吗?您使用的是C代码还是p/invoke?您可能没有正确封送系统\u电源\u功能结构。添加了代码示例。我用的是C#和PInvoke。我确实得到了一些价值观,所以有些东西是有效的,但我想我可能错过了一些东西。那太好了!