|
Overview |
|
|
|
Group |
|
|
|
Quick Info
Windows NT
| Yes
| Win95
| Yes
| Win32s
| Yes
| Import Library
| kernel32.lib
| Header File
| winbase.h
| Unicode
| No
| Platform Notes
| None
|
|
|
SetFilePointer
The SetFilePointer function moves the file pointer of an open file.
DWORD SetFilePointer(
HANDLE hFile,
| // handle of file
| LONG lDistanceToMove,
| // number of bytes to move file pointer
| PLONG lpDistanceToMoveHigh,
| // address of high-order word of distance to move
| DWORD dwMoveMethod
| // how to move
| );
|
|
Parameters
hFile
Identifies the file whose file pointer is to be moved. The file handle must
have been created with GENERIC_READ or GENERIC_WRITE access to the file.
lDistanceToMove
Specifies the number of bytes to move the file pointer. A positive value moves
the pointer forward in the file and a negative value moves it backward.
lpDistanceToMoveHigh
Points to the high-order word of the 64-bit distance to move. If the value of
this parameter is NULL, SetFilePointer can operate only on files whose maximum size is 2^32 2. If this parameter is specified, the maximum file size is 2^64 2. This parameter also receives the high-order word of the new value of the
file pointer.
dwMoveMethod
Specifies the starting point for the file pointer move. This parameter can be
one of the following values:
Value
| Meaning
| FILE_BEGIN
| The starting point is zero or the beginning of the file. If FILE_BEGIN is
specified, DistanceToMove is interpreted as an unsigned location for the new file pointer.
| FILE_CURRENT
| The current value of the file pointer is the starting point.
| FILE_END
| The current end-of-file position is the starting point.
|
Return Values
If the SetFilePointer function succeeds, the return value is the low-order doubleword of the new
file pointer, and if lpDistanceToMoveHigh is not NULL, the function puts the high-order doubleword of the new file
pointer into the LONG pointed to by that parameter.
If the function fails and lpDistanceToMoveHigh is NULL, the return value is 0xFFFFFFFF. To get extended error information,
call GetLastError.
If the function fails, and lpDistanceToMoveHigh is non-NULL, the return value is 0xFFFFFFFF and GetLastError will return a value other than NO_ERROR.
Remarks
You cannot use the SetFilePointer function with a handle to a nonseeking device, such as a pipe or a
communications device. To determine the file type for hFile, use the GetFileType function.
You should be careful when setting the file pointer in a multithreaded
application. For example, an application whose threads share a file handle, update the
file pointer, and read from the file must protect this sequence by using a
critical section object or mutex object. For more information about these objects,
see Mutex Objects and Critical Section Objects.
If the hFile file handle was opened with the FILE_FLAG_NO_BUFFERING flag set, an
application can move the file pointer only to sector-aligned positions. A sector-aligned
position is a position that is a whole number multiple of the volume's sector
size. An application can obtain a volume's sector size by calling the GetDiskFreeSpace function. If an application calls SetFilePointer with distance-to-move values that result in a position that is not
sector-aligned and a handle that was opened with FILE_FLAG_NO_BUFFERING, the function
fails, and GetLastError returns ERROR_INVALID_PARAMETER.
Note that if the return value is 0xFFFFFFFF and if lpDistanceToMoveHigh is non-NULL, an application must call GetLastError to determine whether the function has succeeded or failed. The following
sample code illustrates this point:
//
// Case One: calling the function with
// lpDistanceToMoveHigh == NULL
// try to move hFile's file pointer some distance
dwPointer = SetFilePointer (hFile, lDistance,
NULL, FILE_BEGIN) ;
// if we failed ...
if (dwPointer == 0xFFFFFFFF) {
// obtain the error code
dwError = GetLastError() ;
// deal with that failure
.
.
.
} // end of error handler
//
// Case Two: calling the function with
// lpDistanceToMoveHigh != NULL
// try to move hFile's file pointer some huge distance
dwPointerLow = SetFilePointer (hFile, lDistanceLow,
& lDistanceHigh, FILE_BEGIN) ;
// if we failed ...
if (dwPointerLow == 0xFFFFFFFF
&&
(dwError = GetLastError()) != NO_ERROR ){
// deal with that failure
.
.
.
} // end of error handler
See Also
GetDiskFreeSpace, GetFileType, ReadFile, ReadFileEx, WriteFile, WriteFileEx
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|