IStream::Seek

This method changes the seek pointer to a new location relative to the current seek pointer or the beginning or end of the stream.

At a Glance

Header file: Objidl.h
Windows CE versions: 2.0 and later

Syntax

HRESULT Seek( ULARGE_INTEGER dlibMove, DWORD dwOrigin,
ULARGE_INTEGER plibNewPosition );

Parameters

dlibMove

[in] Displacement to be added to the location indicated by dwOrigin. If dwOrigin is STREAM_SEEK_SET, this is interpreted as an unsigned value rather than signed.

dwOrigin

[in] Specifies the origin for the displacement specified in dlibMove. The origin can be the beginning of the file, the current seek pointer, or the end of the file.

plibNewPosition

[out] Pointer to the location where this method writes the value of the new seek pointer from the beginning of the stream. You can set this pointer to NULL to indicate that you are not interested in this value. In this case, this method does not provide the new seek pointer.

Return Values

One of the values described in the following table is returned.

Value Description
S_OK The seek pointer has been successfully adjusted.
E_PENDING Asynchronous Storage only: Part or all of the stream’s data is currently unavailable.
STG_E_INVALIDPOINTER The value of the plibNewPosition parameter is not valid.
STG_E_INVALIDFUNCTION The value of the dwOrigin parameter is not valid.
STG_E_REVERTED The object has been invalidated by a revert operation above it in the transaction tree.

Remarks

IStream::Seek changes the seek pointer so subsequent reads and writes can take place at a different location in the stream object. It is an error to seek before the beginning of the stream. It is not, however, an error to seek past the end of the stream. Seeking past the end of the stream is useful for subsequent writes, as the stream will at that time be extended to the seek position immediately before the write is done.

You can also use this method to obtain the current value of the seek pointer by calling this method with the dwOrigin parameter set to STREAM_SEEK_CUR and the dlibMove parameter set to 0 so the seek pointer is not changed. The current seek pointer is returned in the plibNewPosition parameter.