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);
        }
Beispiel #2
0
        private void ExecuteHibernateFileAction(HibernateFileAction fileAction)
        {
            int    inputBufferLength = Marshal.SizeOf <bool>();
            IntPtr inputBuffer       = Marshal.AllocCoTaskMem(inputBufferLength);

            Marshal.WriteByte(inputBuffer, (byte)fileAction);

            var retval = PowerManagementInteroperation.CallNtPowerInformation(
                (int)PowerInformationLevel.SystemReserveHiberFile,
                inputBuffer,
                inputBufferLength,
                IntPtr.Zero,
                0);

            Marshal.FreeHGlobal(inputBuffer);
            if (retval == PowerManagementInteroperation.STATUS_SUCCESS)
            {
            }
            else
            {
                throw new Win32Exception();
            }
        }
 public void WriteBytes(IntPtr pointer, HibernateFileAction fileActions)
 {
     TryDo(() => Marshal.WriteByte(ptr: pointer, val: (byte)fileActions));
 }