public static void ShowSystemPowerInformation() { SystemPowerInformation state = new SystemPowerInformation(); var ptr = IntPtr.Zero; try { ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemPowerInformation))); uint retval = CallNtPowerInformation( SYSTEM_POWER_INFORMATION_LEVEL, IntPtr.Zero, 0, ptr, Marshal.SizeOf(typeof(SystemPowerInformation)) ); if (retval == STATUS_SUCCESS) { state = Marshal.PtrToStructure <SystemPowerInformation>(ptr); } } finally { if (ptr != IntPtr.Zero) { Marshal.FreeCoTaskMem(ptr); } } ShowAllPowerInfo(state); }
public static extern uint CallNtPowerInformation( int InformationLevel, IntPtr lpInputBuffer, int nInputBufferSize, out SystemPowerInformation spi, int nOutputBufferSize );
public SystemPowerInformation GetSystemPowerInformation() { IntPtr systemBatteryStatePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemPowerInformation))); int status = CallNtPowerInformation(SystemPowerInformation, IntPtr.Zero, 0, systemBatteryStatePtr, Marshal.SizeOf(typeof(SystemPowerInformation))); SystemPowerInformation spInformation = (SystemPowerInformation)Marshal.PtrToStructure(systemBatteryStatePtr, typeof(SystemPowerInformation)); Marshal.FreeHGlobal(systemBatteryStatePtr); return(spInformation); }
internal static extern uint CallNtPowerInformation(PowerInformationLevel informationLevel, IntPtr inputBuffer, int inputBufferSize, out SystemPowerInformation outputBuffer, int outputBufferSize);
public static extern PowerInformationStatus CallNtPowerInformation( PowerInformationLevel informationLevel, IntPtr inputBuffer, int inputBufferSize, out SystemPowerInformation systemBatteryState, int outputBufferSize);
private static extern NtStatus CallNtPowerInformation( PowerInformationLevel informationLevel, IntPtr inputBuffer, int inputBufferSize, out SystemPowerInformation outputBuffer, int outputBufferSize);