private T GetStructure <T>(PowerInformationLevel informationLevel) { IntPtr lpInBuffer = IntPtr.Zero; int inputBufSize = 0; int outputPtrSize = _marshal.SizeOf <T>(); IntPtr outputPtr = _marshal.AllocateMemory(size: outputPtrSize); PointerResult result = _powerManagementInterop.CallNtPowerInformation( informationLevel: informationLevel, inputBuffer: lpInBuffer, inputBufSize: inputBufSize, outputBuffer: outputPtr, outputBufferSize: outputPtrSize); _marshal.ReleasePointer(lpInBuffer); if (result.IsSuccessful) { T properties = _marshal.ToProperties <T>(outputPtr); _marshal.ReleasePointer(outputPtr); return(properties); } else { _marshal.ReleasePointer(outputPtr); throw new Win32Exception(); } }
private PointerResult HibernateFileAction(HibernateFileAction fileAction) { int intSize = _marshal.SizeOf <bool>(); IntPtr pointer = _marshal.AllocateMemory(intSize); _marshal.WriteBytes(pointer, fileAction); const int outputBufferSize = 0; PointerResult result = _powerManagementInterop.CallNtPowerInformation( informationLevel: PowerInformationLevel.SystemReserveHiberFile, inputBuffer: pointer, inputBufSize: intSize, outputBuffer: IntPtr.Zero, outputBufferSize: outputBufferSize); _marshal.ReleasePointer(pointer); return(result); }