private static bool TryGetDevice(uint index, out string result, QueryInterpretationFlags?flags = null) { uint size = 0; QueryInterpretationFlags targetFlags = flags ?? flagsAll; PowerManagement.DevicePowerEnumDevices(index, targetFlags, flagsQuery, IntPtr.Zero, ref size); if (size > 0) { var buffer = Marshal.AllocHGlobal((int)size); try { if (PowerManagement.DevicePowerEnumDevices(index, targetFlags, flagsQuery, buffer, ref size) && buffer != IntPtr.Zero) { result = Marshal.PtrToStringUni(buffer); return(true); } } finally { Marshal.FreeHGlobal(buffer); } } result = null; return(false); }
public static extern bool DevicePowerEnumDevices(uint queryIndex, QueryInterpretationFlags queryInterpretationFlags, QueryFlags queryFlags, IntPtr pReturnBuffer, ref uint pBufferSize);