Retrieving a File Pointer

The SetFilePointer function can be used to query the current file pointer position, by specifying a move method of FILE_CURRENT and a distance of zero.

HANDLE hFile; 
 
DWORD dwCurrentFilePosition; 
 
dwCurrentFilePosition = SetFilePointer( 
    hFile, // must have GENERIC_READ and/or GENERIC_WRITE 
    0,     // do not move pointer 
    NULL,  // hFile is not large enough to need this pointer 
    FILE_CURRENT);  // provides offset from current position 
 

The following macro can be used to obtain the current file pointer position for files smaller than 2 gigabytes in size:

#define GetFilePointer(hFile) SetFilePointer(hFile, 0, NULL, FILE_CURRENT)
 

To get the current file positions on larger files, use the following:

#define GetVLFilePointer(hFile, lpPositionHigh) \
        (*lpPositionHigh = 0, \
        SetFilePointer(hFile, 0, lpPositionHigh, FILE_CURRENT))
 

where lpPositionHigh is a value of type PLONG. The high order long word of the current file position will be returned in lpPositionHigh.