internal static extern SafeFileHandle CreateFile(
     string lpFileName,
     DesiredAccesses dwDesiredAccess,
     ShareModes dwShareMode,
     ref SECURITY_ATTRIBUTES lpSecurityAttributes,
     int dwCreationDisposition,
     FileFlags dwFlagsAndAttributes,
     int hTemplateFile);
Exemple #2
0
        public SafeFileHandle OpenDevice(string devicePath, DesiredAccesses deviceAccesses, ShareModes shareModes, FileFlags flags)
        {
            if (IsThrow)
            {
                throw new Exception("TestException");
            }
            var returnValue = IsFailureHandle ? IntPtr.Zero : new IntPtr(1);

            IsOpenDevice = true;
            return(new SafeFileHandle(returnValue, true));
        }
        public SafeFileHandle OpenDevice(string devicePath, DesiredAccesses deviceAccesses, ShareModes shareModes, FileFlags flags)
        {
            if (devicePath == null)
            {
                throw new ArgumentNullException($"{nameof(devicePath)} is null");
            }

            var security = new SECURITY_ATTRIBUTES(true);

            SafeFileHandle result = NativeMethods.CreateFile(devicePath, deviceAccesses, shareModes, ref security, NativeMethods.OPEN_EXISTING, flags, 0);

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

            return(result);
        }
Exemple #4
0
 public static extern SafeFileHandle CreateFile(string lpFileName, DesiredAccesses dwDesiredAccess, ShareModes dwShareMode, IntPtr lpSecurityAttributes, CreationDispositions dwCreationDisposition, FlagsAndAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
Exemple #5
0
 public static extern SafeFileHandle CreateFile(string lpFileName, DesiredAccesses dwDesiredAccess, ShareModes dwShareMode, IntPtr lpSecurityAttributes, CreationDispositions dwCreationDisposition, FlagsAndAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);