コード例 #1
0
        public SystemBatteryState GetSystemBatteryState()
        {
            IntPtr status = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemBatteryState)));

            Win32FunctionInvokeWrapper.CallNtPowerInformation(INFORMATION_LEVEL.SystemBatteryState, IntPtr.Zero, 0, status, (UInt32)Marshal.SizeOf(typeof(SystemBatteryState)));
            return((SystemBatteryState)Marshal.PtrToStructure(status, typeof(SystemBatteryState)));
        }
コード例 #2
0
        public DateTime GetLastSleepTime()
        {
            IntPtr status = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(long)));

            Win32FunctionInvokeWrapper.CallNtPowerInformation(INFORMATION_LEVEL.LastSleepTime, (IntPtr)null, 0, status, (UInt32)Marshal.SizeOf(typeof(long)));
            long lastSleepTime = (long)Marshal.PtrToStructure(status, typeof(long));

            return(DateTime.FromFileTime(lastSleepTime));
        }