私はC#でCallNtPowerInformation関数を使用するのに本当に苦労しています。WindowsSystemExecutionStateを取得する必要があります。(ここにリストされている可能な値)。
適切なC#署名を見つけました:
[DllImport("powrprof.dll", SetLastError = true)]
private static extern UInt32 CallNtPowerInformation(
Int32 InformationLevel,
IntPtr lpInputBuffer,
UInt32 nInputBufferSize,
IntPtr lpOutputBuffer,
UInt32 nOutputBufferSize
);
次に、情報レベル16を使用して「SystemExecutionState」を読み取る必要があります。これが私がこれまでに持っているコードです:
IntPtr status = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(ulong)));
UInt32 returnValue = CallNtPowerInformation(
16,
(IntPtr)null,
0,
status, (
UInt32)Marshal.SizeOf(typeof(ulong)));
Marshal.FreeCoTaskMem(status);
Microsoftのドキュメントによると:
lpOutputBufferバッファーは、システム実行状態バッファーを含むULONG値を受け取ります。
IntPtrからULONG値を取得するにはどうすればよいですか?