Moves the file pointer of an open file.
DWORD SetFilePointer( HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod );
hFile
lDistanceToMove
lpDistanceToMove
moves the file pointer forward in the file; a negative value moves the file pointer backward. Note that you cannot use a negative value to move back past beyond the beginning of a file.
lpDistanceToMoveHigh
dwMoveMethod
FILE_BEGIN | Zero, or the beginning of the file. |
FILE_CURRENT | The file pointer's current value. |
FILE_END | The current EOF position. |
You can use SetFilePointer to query the current file pointer position. To do this, specify a move method of FILE_CURRENT and a distance of zero.
It is not an error to set the file pointer to a position beyond the file's end. The file size does not increase until you call WriteFile. A write operation increases the file size to the file pointer position plus the size of the buffer written, leaving the intervening bytes uninitialized.
Note: SetFilePointer cannot be used to move the file pointer beyond the maximum file size, which is 0xFFFFFFFF. If SetFilePointer is called to move the pointer beyond 0xFFFFFFFF, the pointer is set at 0xFFFFFFFF. In this case, the return value is 0xFFFFFFFF, but GetLastError returns NO_ERROR.
You can use SetFilePointer to determine the file length. To do this, use FILE_END for dwMoveMethod and seek to location zero. The returned file offset is the file's length. However, this practice can have unintended side effects, such as failing to save the current file pointer the application uses to return to that location.
If the value is 0xFFFFFFFF (a valid file pointer but also the Failure code), you must check GetLastError to determine whether an error occurred. If an error occurred, a value other than NO_ERROR returns.
If the new file pointer would be a negative value, the function fails, the file pointer does not move, and GetLastError returns ERROR_NEGATIVE_SEEK.
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/winbase.h | windows.h | iwin32.lib |
Note
This function operates in the real-time portion of your application.
ReadFile, WriteFile, iwin32 API, iwin32 Overview