CreateFile() private method

private CreateFile ( string lpFileName, uint dwDesiredAccess, int dwShareMode, SECURITY_ATTRIBUTES &lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile ) : IntPtr
lpFileName string
dwDesiredAccess uint
dwShareMode int
lpSecurityAttributes SECURITY_ATTRIBUTES
dwCreationDisposition int
dwFlagsAndAttributes int
hTemplateFile int
return System.IntPtr
Example #1
0
        private static IntPtr OpenDeviceIO(string devicePath, DeviceMode deviceMode, uint deviceAccess)
        {
            NativeMethods.SECURITY_ATTRIBUTES lpSecurityAttributes = default(NativeMethods.SECURITY_ATTRIBUTES);
            int dwFlagsAndAttributes = 0;

            if (deviceMode == DeviceMode.Overlapped)
            {
                dwFlagsAndAttributes = 1073741824;
            }
            lpSecurityAttributes.lpSecurityDescriptor = IntPtr.Zero;
            lpSecurityAttributes.bInheritHandle       = true;
            lpSecurityAttributes.nLength = Marshal.SizeOf((object)lpSecurityAttributes);
            return(NativeMethods.CreateFile(devicePath, deviceAccess, 3, ref lpSecurityAttributes, 3, dwFlagsAndAttributes, 0));
        }
Example #2
0
        private static IntPtr OpenDeviceIO(string devicePath, DeviceMode deviceMode, uint deviceAccess, ShareMode shareMode)
        {
            var security = new NativeMethods.SECURITY_ATTRIBUTES();
            var flags    = 0;

            if (deviceMode == DeviceMode.Overlapped)
            {
                flags = NativeMethods.FILE_FLAG_OVERLAPPED;
            }

            security.lpSecurityDescriptor = IntPtr.Zero;
            security.bInheritHandle       = true;
            security.nLength = Marshal.SizeOf(security);

            return(NativeMethods.CreateFile(devicePath, deviceAccess, (int)shareMode, ref security, NativeMethods.OPEN_EXISTING, flags, 0));
        }
Example #3
0
        private static IntPtr OpenDeviceIO(string devicePath, DeviceMode deviceMode, uint deviceAccess, ShareMode shareMode)
        {
            var security = new NativeMethods.SecurityAttributes();
            var flags    = 0;

            if (deviceMode == DeviceMode.Overlapped)
            {
                flags = NativeMethods.FileFlagOverlapped;
            }

            security.lpSecurityDescriptor = IntPtr.Zero;
            security.bInheritHandle       = true;
            security.nLength = Marshal.SizeOf(security);

            return(NativeMethods.CreateFile(devicePath, deviceAccess, (int)shareMode, ref security, NativeMethods.OpenExisting, flags, 0));
        }
Example #4
0
        private SafeFileHandle OpenHandle(String devicePathName, Boolean isExclusive)
        {
            SafeFileHandle hidHandle;

            try
            {
                if (isExclusive)
                {
                    hidHandle = NativeMethods.CreateFile(devicePathName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, 0, IntPtr.Zero, NativeMethods.OpenExisting, 0, 0);
                }
                else
                {
                    hidHandle = NativeMethods.CreateFile(devicePathName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OpenExisting, 0, 0);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(hidHandle);
        }