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); }
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) }; }