最终,我想确定程序运行所在的计算机是笔记本电脑还是台式机。我想使用LidPresent标志对JNA和msn的PowrProf lib GetPwrCapabilities Function进行此操作。

SYSTEM_POWER_CAPABILITIES结构的一部分(这是GetPwrCapabilities()方法的参数)

  BYTE                    spare2[3];
  BYTE                    spare3[8];
  BATTERY_REPORTING_SCALE BatteryScale[3];
  SYSTEM_POWER_STATE      AcOnLineWake;


SYSTEM_POWER_STATE枚举:

typedef enum _SYSTEM_POWER_STATE {
  PowerSystemUnspecified   = 0,
  PowerSystemWorking       = 1,
  PowerSystemSleeping1     = 2,
  PowerSystemSleeping2     = 3,
  PowerSystemSleeping3     = 4,
  PowerSystemHibernate     = 5,
  PowerSystemShutdown      = 6,
  PowerSystemMaximum       = 7
} SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;


枚举已在SO上进行了解释,但我不确定是否正确执行此操作,因为出现此错误:


线程“主”中的异常java.lang.IllegalArgumentException:无效
课堂上的结构场
JNAPlayground $ PowrProf $ SYSTEM_POWER_CAPABILITIES,字段名称
'AcOnLineWake',接口JNAPlayground $ PowrProf $ SYSTEM_POWER_STATE:
不支持类型“ JNAPlayground $ PowrProf $ SYSTEM_POWER_STATE”:
类型“ JNAPlayground $ PowrProf $ SYSTEM_POWER_STATE”的本机大小为
未知


您能否为我提供指导或为我指出正确的方向:
-数组
-枚举(如果我错了)
-如果我没有导入足够的库

到目前为止,我的Java代码:

public interface PowrProf extends StdCallLibrary
{
    PowrProf INSTANCE = (PowrProf) Native.loadLibrary(
            "C:\\WINDOWS\\system32\\PowrProf.dll", PowrProf.class);

    public static interface SYSTEM_POWER_STATE
    {
        public static final int owerSystemUnspecified = 0;
        public static final int PowerSystemWorking = 1;
        public static final int PowerSystemSleeping1 = 2;
        public static final int PowerSystemSleeping2 = 3;
        public static final int PowerSystemSleeping3 = 4;
        public static final int PowerSystemHibernate = 5;
        public static final int PowerSystemShutdown = 6;
        public static final int PowerSystemMaximum = 7;

    }

    public static class BATTERY_REPORTING_SCALE extends Structure
    {
        public long Granularity;
        public long Capacity;
    }

    public static class SYSTEM_POWER_CAPABILITIES extends Structure
    {
        public boolean PowerButtonPresent;
        public boolean SleepButtonPresent;
        public boolean LidPresent;
        public boolean SystemS1;
        public boolean SystemS2;
        public boolean SystemS3;
        public boolean SystemS4;
        public boolean SystemS5;
        public boolean HiberFilePresent;
        public boolean FullWake;
        public boolean VideoDimPresent;
        public boolean ApmPresent;
        public boolean UpsPresent;
        public boolean ThermalControl;
        public boolean ProcessorThrottle;
        public int ProcessorMinThrottle;
        public int ProcessorMaxThrottle;
        public boolean FastSystemS4;
        public int spare2[] = new int[3];
        public boolean DiskSpinDown;
        public int spare3[] = new int[8];
        public boolean SystemBatteriesPresent;
        public boolean BatteriesAreShortTerm;
        public BATTERY_REPORTING_SCALE BatteryScale[] =  new BATTERY_REPORTING_SCALE[3];
        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;
    }

    void GetPwrCapabilities( SYSTEM_POWER_CAPABILITIES result );
}


谢谢,
埃里克

最佳答案

在google之后,我尝试重新访问jna的主页,而忽略此处的其他枚举问题。枚举的映射为here。我的代码现在显示有盖子!

import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.win32.StdCallLibrary;

public class JNAPlayground
{

    public interface PowrProf extends StdCallLibrary
    {
        PowrProf INSTANCE = (PowrProf) Native.loadLibrary(
                "C:\\WINDOWS\\system32\\PowrProf.dll", PowrProf.class);

        public static class BATTERY_REPORTING_SCALE extends Structure
        {
            public long Granularity;
            public long Capacity;
        }

        public static class SYSTEM_POWER_CAPABILITIES extends Structure
        {
            public boolean PowerButtonPresent;
            public boolean SleepButtonPresent;
            public boolean LidPresent;
            public boolean SystemS1;
            public boolean SystemS2;
            public boolean SystemS3;
            public boolean SystemS4;
            public boolean SystemS5;
            public boolean HiberFilePresent;
            public boolean FullWake;
            public boolean VideoDimPresent;
            public boolean ApmPresent;
            public boolean UpsPresent;
            public boolean ThermalControl;
            public boolean ProcessorThrottle;
            public int ProcessorMinThrottle;
            public int ProcessorMaxThrottle;
            public boolean FastSystemS4;
            public int spare2[] = new int[3];
            public boolean DiskSpinDown;
            public int spare3[] = new int[8];
            public boolean SystemBatteriesPresent;
            public boolean BatteriesAreShortTerm;
            public BATTERY_REPORTING_SCALE BatteryScale[] =  new BATTERY_REPORTING_SCALE[3];
            public int AcOnLineWake;
            public int SoftLidWake;
            public int RtcWake;
            public int MinDeviceWakeState;
            public int DefaultLowLatencyWake;
        }

        void GetPwrCapabilities( SYSTEM_POWER_CAPABILITIES result );
    }

    public static void main( String[] args )
    {
        PowrProf lib2 = PowrProf.INSTANCE;
        PowrProf.SYSTEM_POWER_CAPABILITIES systemPOWERCAPABILITIES = new PowrProf.SYSTEM_POWER_CAPABILITIES();
        lib2.GetPwrCapabilities(systemPOWERCAPABILITIES);

        System.out.println("Lid present:" + systemPOWERCAPABILITIES.LidPresent);
    }
}

08-03 12:00