예제 #1
0
        internal static IntPtr OpenDeviceIO(string devicePath, DeviceMode deviceMode, uint deviceAccess)
        {
            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, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, ref security, NativeMethods.OPEN_EXISTING, flags, 0);
        }
예제 #2
0
파일: Device.cs 프로젝트: HaKDMoDz/GNet
        void CreateOverlappedEvent(out NativeMethods.SECURITY_ATTRIBUTES security, out NativeMethods.OVERLAPPED overlappedEvent)
        {
            security = new NativeMethods.SECURITY_ATTRIBUTES
            {
                lpSecurityDescriptor = IntPtr.Zero,
                bInheritHandle = true,
                nLength = Marshal.SizeOf(cancelEventSecurity)
            };

            overlappedEvent = new NativeMethods.OVERLAPPED
            {
                Offset = 0,
                OffsetHigh = 0,
                hEvent = NativeMethods.CreateEvent(ref cancelEventSecurity, Convert.ToInt32(true), Convert.ToInt32(false), string.Empty)
            };
        }