[DllImport("powrprof.dll", SetLastError=true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool DevicePowerEnumDevices(uint queryIndex, QueryInterpretationFlags queryInterpretationFlags, QueryFlags queryFlags, IntPtr pReturnBuffer, ref uint pBufferSize);
Declare Function DevicePowerEnumDevices Lib "powrprof.dll" (TODO) As TODO
QueryInterpretationFlags, QueryFlags
Do you know one? Please contribute it!
If pReturnBuffer is NULL, pBufferSize will be filled with the size needed to return the data.
Please add some!
const int MAX_PATH = 261;
if (!DevicePowerOpen(0))
return; // error
uint size = MAX_PATH;
IntPtr ptrBuffer = Marshal.AllocHGlobal((int)size);
uint index = 0;
bool result = false;
try
{
while ((ptrBuffer != IntPtr.Zero) &&
(result = DevicePowerEnumDevices(index, QueryInterpretationFlags.DEVICEPOWER_FILTER_DEVICES_PRESENT, QueryFlags.PDCAP_D2_SUPPORTED, ptrBuffer, ref size)) != false)
{
string strBuffer = Marshal.PtrToStringUni(ptrBuffer);
string str = string.Format("Device name: {0}\n", strBuffer);
index++;
}
}
finally
{
Marshal.FreeHGlobal(ptrBuffer);
DevicePowerClose();
}