Q:

IAsyncReader::SyncRead method

How can I interpret a "fill my buffer request" that returns S_FALSE ("I could read some but not all of the data you requested"), given the signature is:
HRESULT SyncRead(LONGLONG llPosition, LONG     lLength, BYTE     *pBuffer);

Specifically, how many bytes of the buffer are valid when the interface returns S_FALSE? 
I need to know that, right? Perhaps I am being daft, but I do not see it.

A:

See this piece of code from this file on Microsoft's own git:
// sync read. works in stopped state as well as run state.
// need not be aligned. Will fail if read is beyond actual total
// length.
STDMETHODIMP SyncRead(
                  LONGLONG llPosition,  // absolute file position
                  LONG lLength,         // nr bytes required
                  BYTE* pBuffer);       // write data here

// return total length of stream, and currently available length.
// reads for beyond the available length but within the total length will
// normally succeed but may block for a long period.
STDMETHODIMP Length(
                  LONGLONG* pTotal,
                  LONGLONG* pAvailable);

According to these two documented declarations, I think it's pretty safe to deduce bytes count read the following way. Say you want to read 70 bytes from position 800:
LONGLONG total, available;
pReader->Length(&total, &available);

LONG bytesRead = 70;
LONGLONG position = 800; 
if (S_FALSE == readerPtr->SyncRead(800, bytesRead, bufferPtr))
    bytesRead = total - position;

As if it fails, then the number of bytes it could have read is only limited by the total size.

