diff --git a/PInvoke/Kernel32/FileApi.cs b/PInvoke/Kernel32/FileApi.cs index dc206ff8..056fe926 100644 --- a/PInvoke/Kernel32/FileApi.cs +++ b/PInvoke/Kernel32/FileApi.cs @@ -28,7 +28,7 @@ namespace Vanara.PInvoke [PInvokeData("fileapi.h")] public const uint INVALID_FILE_SIZE = 0xFFFFFFFF; /// A value returned then a file pointer cannot be set. - [PInvokeData("fileapi.h")] public const int INVALID_SET_FILE_POINTER = -1; + [PInvokeData("fileapi.h")] public const uint INVALID_SET_FILE_POINTER = unchecked((uint)-1); /// Alway open, creating new if doesn't exist. [PInvokeData("fileapi.h")] public const uint OPEN_ALWAYS = 4; @@ -341,7 +341,7 @@ namespace Vanara.PInvoke var ar = OverlappedAsync.SetupOverlappedFunction(hFile, requestCallback, stateObject); fixed (byte* pIn = buffer) { - var ret = ReadFile(hFile, pIn, numberOfBytesToRead, IntPtr.Zero, ar.Overlapped); + var ret = ReadFile(hFile, pIn, numberOfBytesToRead, null, ar.Overlapped); return OverlappedAsync.EvaluateOverlappedFunction(ar, ret); } } @@ -3814,7 +3814,7 @@ namespace Vanara.PInvoke [DllImport(Lib.Kernel32, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("FileAPI.h", MSDNShortId = "aa365467")] - public static extern unsafe bool ReadFile(HFILE hFile, byte* lpBuffer, uint nNumberOfBytesToRead, IntPtr lpNumberOfBytesRead, NativeOverlapped* lpOverlapped); + public static extern unsafe bool ReadFile(HFILE hFile, byte* lpBuffer, uint nNumberOfBytesToRead, [Optional] uint* lpNumberOfBytesRead, NativeOverlapped* lpOverlapped); /// /// Reads data from the specified file or input/output (I/O) device. Reads occur at the position specified by the file pointer if @@ -4305,6 +4305,89 @@ namespace Vanara.PInvoke [PInvokeData("FileAPI.h", MSDNShortId = "aa365541")] public static extern uint SetFilePointer([In] HFILE hFile, int lDistanceToMove, ref int lpDistanceToMoveHigh, SeekOrigin dwMoveMethod); + /// + /// Moves the file pointer of the specified file. + /// + /// This function stores the file pointer in two LONG values. To work with file pointers that are larger than a single + /// LONG value, it is easier to use the SetFilePointerEx function. + /// + /// + /// + /// A handle to the file. + /// + /// The file handle must be created with the GENERIC_READ or GENERIC_WRITE access right. For more information, see File + /// Security and Access Rights. + /// + /// + /// + /// The low order 32-bits of a signed value that specifies the number of bytes to move the file pointer. + /// + /// If lpDistanceToMoveHigh is not NULL, lpDistanceToMoveHigh and lDistanceToMove form a single 64-bit signed value that + /// specifies the distance to move. + /// + /// + /// If lpDistanceToMoveHigh is NULL, lDistanceToMove is a 32-bit signed value. A positive value for lDistanceToMove moves the + /// file pointer forward in the file, and a negative value moves the file pointer back. + /// + /// + /// + /// A pointer to the high order 32-bits of the signed 64-bit distance to move. + /// If you do not need the high order 32-bits, this pointer must be set to NULL. + /// + /// When not NULL, this parameter also receives the high order DWORD of the new value of the file pointer. For more + /// information, see the Remarks section in this topic. + /// + /// + /// + /// The starting point for the file pointer move. + /// This parameter can be one of the following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// FILE_BEGIN = 0 + /// The starting point is zero or the beginning of the file. + /// + /// + /// FILE_CURRENT = 1 + /// The starting point is the current value of the file pointer. + /// + /// + /// FILE_END = 2 + /// The starting point is the current end-of-file position. + /// + /// + /// + /// + /// + /// + /// If the function succeeds and lpDistanceToMoveHigh is NULL, the return value is the low-order DWORD of the new file pointer. + /// + /// + /// Note If the function returns a value other than INVALID_SET_FILE_POINTER, the call to SetFilePointer has + /// succeeded. You do not need to call GetLastError. + /// + /// + /// If function succeeds and lpDistanceToMoveHigh is not NULL, the return value is the low-order DWORD of the new file + /// pointer and lpDistanceToMoveHigh contains the high order DWORD of the new file pointer. + /// + /// If the function fails, the return value is INVALID_SET_FILE_POINTER. To get extended error information, call GetLastError. + /// + /// If a new file pointer is a negative value, the function fails, the file pointer is not moved, and the code returned by + /// GetLastError is ERROR_NEGATIVE_SEEK. + /// + /// + /// If lpDistanceToMoveHigh is NULL and the new file position does not fit in a 32-bit value, the function fails and returns INVALID_SET_FILE_POINTER. + /// + /// + // DWORD WINAPI SetFilePointer( _In_ HANDLE hFile, _In_ LONG lDistanceToMove, _Inout_opt_ PLONG lpDistanceToMoveHigh, _In_ DWORD dwMoveMethod); + [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("FileAPI.h", MSDNShortId = "aa365541")] + public static extern uint SetFilePointer([In] HFILE hFile, uint lDistanceToMove, ref uint lpDistanceToMoveHigh, SeekOrigin dwMoveMethod); + /// /// Moves the file pointer of the specified file. ///