internal static extern UInt32 CallNtPowerInformation(
     PowerInformationLevel informationLevel,
     IntPtr inputBuffer,
     UInt32 inputBufferSize,
     out SystemBatteryState outputBuffer,
     UInt32 outputBufferSize
     );
 public static extern uint CallNtPowerInformation(
     PowerInformationLevel informationLevel,
     IntPtr inputBuffer,
     uint inputBufferSize,
     out SystemBatteryState outputBuffer,
     uint outputBufferSize
     );
Esempio n. 3
0
 public static extern uint CallNtPowerInformation(
     InfoLevel informationLevel,
     IntPtr inputBuffer,
     int inputBufferSize,
     [MarshalAs(UnmanagedType.Struct)]
     out SystemBatteryState result,
     int resultSize);
Esempio n. 4
0
        public static void ShowSystemBatteryState()
        {
            SystemBatteryState state = new SystemBatteryState();
            var ptr = IntPtr.Zero;

            try
            {
                ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemBatteryState)));
                uint retval = CallNtPowerInformation(
                    SYSTEM_BATTERY_STATE_LEVEL,
                    IntPtr.Zero,
                    0,
                    ptr,
                    Marshal.SizeOf(typeof(SystemBatteryState))
                    );

                if (retval == STATUS_SUCCESS)
                {
                    state = Marshal.PtrToStructure <SystemBatteryState>(ptr);
                }
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
            ShowAllPowerInfo(state);
        }
 public static extern uint CallNtPowerInformation(
     int InformationLevel,
     IntPtr lpInputBuffer,
     int nInputBufferSize,
     out SystemBatteryState sbs,
     int nOutputBufferSize
     );
Esempio n. 6
0
        public SystemBatteryState GetSystemBatteryState()
        {
            IntPtr systemBatteryStatePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemBatteryState)));
            int    status = CallNtPowerInformation(SystemBatteryState, IntPtr.Zero, 0, systemBatteryStatePtr,
                                                   Marshal.SizeOf(typeof(SystemBatteryState)));
            SystemBatteryState btState = (SystemBatteryState)Marshal.PtrToStructure(systemBatteryStatePtr, typeof(SystemBatteryState));

            Marshal.FreeHGlobal(systemBatteryStatePtr);

            return(btState);
        }
 internal static extern UInt32 CallNtPowerInformation(
      PowerInformationLevel informationLevel,
      IntPtr inputBuffer,
      UInt32 inputBufferSize,
      out SystemBatteryState outputBuffer,
      UInt32 outputBufferSize
 );
 private static extern NtStatus CallNtPowerInformation(
     PowerInformationLevel informationLevel, 
     IntPtr inputBuffer, 
     int inputBufferSize, 
     out SystemBatteryState outputBuffer, 
     int outputBufferSize);