From c07f56ebbb62466fb033528e6c681736a2484639 Mon Sep 17 00:00:00 2001 From: David Hall Date: Sat, 22 Jun 2019 14:16:25 -0600 Subject: [PATCH] Added some Optional attributes --- PInvoke/Kernel32/FileApi.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PInvoke/Kernel32/FileApi.cs b/PInvoke/Kernel32/FileApi.cs index cbbf07b3..4788500c 100644 --- a/PInvoke/Kernel32/FileApi.cs +++ b/PInvoke/Kernel32/FileApi.cs @@ -3654,7 +3654,7 @@ namespace Vanara.PInvoke [DllImport(Lib.Kernel32, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("FileAPI.h", MSDNShortId = "aa365467")] - public static extern bool ReadFile(HFILE hFile, IntPtr lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr lpOverlapped); + public static extern bool ReadFile(HFILE hFile, IntPtr lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, [Optional] IntPtr lpOverlapped); /// /// Reads data from the specified file or input/output (I/O) device. Reads occur at the position specified by the file pointer if @@ -3736,7 +3736,7 @@ namespace Vanara.PInvoke [DllImport(Lib.Kernel32, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("FileAPI.h", MSDNShortId = "aa365467")] - public static extern bool ReadFile(HFILE hFile, byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr lpOverlapped); + public static extern bool ReadFile(HFILE hFile, byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, [Optional] IntPtr lpOverlapped); /// /// @@ -4619,7 +4619,7 @@ namespace Vanara.PInvoke [DllImport(Lib.Kernel32, ExactSpelling = true, SetLastError = true), SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("FileAPI.h", MSDNShortId = "aa365747")] - public static extern bool WriteFile(HFILE hFile, IntPtr lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, IntPtr lpOverlapped); + public static extern bool WriteFile(HFILE hFile, IntPtr lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, [Optional] IntPtr lpOverlapped); /// /// Writes data to the specified file or input/output (I/O) device. @@ -4761,7 +4761,7 @@ namespace Vanara.PInvoke [DllImport(Lib.Kernel32, ExactSpelling = true, SetLastError = true), SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("FileAPI.h", MSDNShortId = "aa365747")] - public static extern bool WriteFile(HFILE hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, IntPtr lpOverlapped); + public static extern bool WriteFile(HFILE hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, [Optional] IntPtr lpOverlapped); /// /// @@ -5370,6 +5370,11 @@ namespace Vanara.PInvoke /// The safe handle instance. /// The result of the conversion. public static implicit operator HFILE(SafeHFILE h) => h.handle; + + /// Performs an implicit conversion from to . + /// The safe handle instance. + /// The result of the conversion. + public static explicit operator SafeHFILE(Microsoft.Win32.SafeHandles.SafeFileHandle h) => new SafeHFILE(h.DangerousGetHandle(), false); } ///