最終,我想確定我的程序運行的機器是筆記本電腦還是臺式機。我想用JNA和msn的PowrProf庫,GetPwrCapabilities Function使用LidPresent標誌來做到這一點。在SYSTEM_POWER_CAPABILITIES
結構的帶有複雜結構的JNA
部分(這對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,但我不知道如果我這樣做是正確的,因爲我得到這個錯誤:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid Structure field in class JNAPlayground$PowrProf$SYSTEM_POWER_CAPABILITIES, field name 'AcOnLineWake', interface JNAPlayground$PowrProf$SYSTEM_POWER_STATE: The type "JNAPlayground$PowrProf$SYSTEM_POWER_STATE" is not supported: Native size for type "JNAPlayground$PowrProf$SYSTEM_POWER_STATE" is unknown
請您指導我或點我在正確的方向爲:
- 該陣列
- 枚舉(如果我有這個毛病)
- 如果我沒有足夠的導入庫
我的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);
}
感謝, 埃裏克
此代碼運行,但它輸出「蓋存在:真正的」我運行在每一臺電腦上。 –
枚舉何去何從? –
@ErikB有沒有解決這個問題的運氣?我面臨着一個類似的問題。請同時回答Bjarke Freund-Hansen的問題,因爲它在你的第二篇文章中被明顯地忽略了。謝謝 – amadib