P/Invoke wrappers around Win32 functions and constants.
Beispiel #1
0
        public ulong SeekU(ulong offset, SeekOrigin origin)
        {
            ulong n = 0;

            if (!DeviceIO.SetFilePointerEx(this.fileHandle, offset, out n, (uint)origin))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            return(n);
        }
Beispiel #2
0
 public override void Close()
 {
     if (this.fileHandle != null)
     {
         DeviceIO.CloseHandle(this.fileHandle);
         this.fileHandle.SetHandleAsInvalid();
         this.fileHandle = null;
     }
     base.Close();
 }
Beispiel #3
0
        public unsafe void Write(byte[] buffer, uint offset, uint count)
        {
            uint n = 0;

            fixed(byte *p = buffer)
            {
                if (!DeviceIO.WriteFile(this.fileHandle, p + offset, count, &n, IntPtr.Zero))
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
            }
        }
Beispiel #4
0
        private SafeFileHandle openFile(string id, FileAccess desiredAccess)
        {
            uint access;

            switch (desiredAccess)
            {
            case FileAccess.Read:
                access = DeviceIO.GENERIC_READ;
                break;

            case FileAccess.Write:
                access = DeviceIO.GENERIC_WRITE;
                break;

            case FileAccess.ReadWrite:
                access = DeviceIO.GENERIC_READ | DeviceIO.GENERIC_WRITE;
                break;

            default:
                access = DeviceIO.GENERIC_READ;
                break;
            }

            SafeFileHandle ptr = DeviceIO.CreateFile(
                id,
                access,
                DeviceIO.FILE_SHARE_WRITE,
                IntPtr.Zero,
                DeviceIO.OPEN_EXISTING,
                DeviceIO.FILE_FLAG_WRITE_THROUGH,
                IntPtr.Zero);

            if (ptr.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            return(ptr);
        }