Migrated to CsWin32 #1

Merged
nefarius merged 14 commits from nefarius/bugfix/refactoring into master 2024-07-13 15:32:14 +02:00
2 changed files with 3 additions and 10 deletions
Showing only changes of commit eec290ae8f - Show all commits

View File

@ -190,7 +190,7 @@ public partial class SerialPort : IDisposable
private void InternalClose() private void InternalClose()
{ {
Win32Com.CancelIo(_hPort.DangerousGetHandle()); PInvoke.CancelIo(_hPort);
if (_rxThread != null) if (_rxThread != null)
{ {
_rxThread.Abort(); _rxThread.Abort();
@ -542,7 +542,7 @@ public partial class SerialPort : IDisposable
{ {
if (Marshal.GetLastWin32Error() == (int)WIN32_ERROR.ERROR_IO_PENDING) if (Marshal.GetLastWin32Error() == (int)WIN32_ERROR.ERROR_IO_PENDING)
{ {
Win32Com.CancelIo(_hPort.DangerousGetHandle()); PInvoke.CancelIo(_hPort);
gotBytes = 0; gotBytes = 0;
} }
else else

View File

@ -20,14 +20,7 @@ internal class Win32Com
[DllImport("kernel32.dll")] [DllImport("kernel32.dll")]
internal static extern Boolean GetHandleInformation(IntPtr hObject, out UInt32 lpdwFlags); 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")] [DllImport("kernel32.dll")]
internal static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar); internal static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar);