From eec290ae8fac3ef0a3a34a78181c7679467bee9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Sat, 13 Jul 2024 15:19:51 +0200 Subject: [PATCH] More migrations --- Nefarius.Peripherals.SerialPort/SerialPort.cs | 4 ++-- Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Nefarius.Peripherals.SerialPort/SerialPort.cs b/Nefarius.Peripherals.SerialPort/SerialPort.cs index 8c8d25d..9dbe232 100644 --- a/Nefarius.Peripherals.SerialPort/SerialPort.cs +++ b/Nefarius.Peripherals.SerialPort/SerialPort.cs @@ -190,7 +190,7 @@ public partial class SerialPort : IDisposable private void InternalClose() { - Win32Com.CancelIo(_hPort.DangerousGetHandle()); + PInvoke.CancelIo(_hPort); if (_rxThread != null) { _rxThread.Abort(); @@ -542,7 +542,7 @@ public partial class SerialPort : IDisposable { if (Marshal.GetLastWin32Error() == (int)WIN32_ERROR.ERROR_IO_PENDING) { - Win32Com.CancelIo(_hPort.DangerousGetHandle()); + PInvoke.CancelIo(_hPort); gotBytes = 0; } else diff --git a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs index a535791..9d34003 100644 --- a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs +++ b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs @@ -20,14 +20,7 @@ internal class Win32Com [DllImport("kernel32.dll")] internal static extern Boolean GetHandleInformation(IntPtr hObject, out UInt32 lpdwFlags); - - [DllImport("kernel32.dll")] - internal static extern Boolean CancelIo(IntPtr hFile); - - [DllImport("kernel32.dll", SetLastError = true)] - internal static extern Boolean ReadFile(IntPtr hFile, [Out] Byte[] lpBuffer, UInt32 nNumberOfBytesToRead, - out UInt32 nNumberOfBytesRead, IntPtr lpOverlapped); - + [DllImport("kernel32.dll")] internal static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar);