Example of Accessing a File I/O Buffer

The following code fragment is based on the ReversePlay example function discussed in “Example of RIFF File I/O,” earlier in this chapter. In this example, direct-buffer access is used to read waveform data from a file.

HMMIO       hmmio;
MMIOINFO    mmioinfo;
DWORD       dwDataSize;
DWORD       dwCount;
HPSTR       hptr;
.
.
.

/* Get information on the file I/O buffer.
 */
if (mmioGetInfo(hmmio, &mmioinfo, 0))
{
    Error("Failed to get I/O buffer info.");
    ...
    mmioClose(hmmio, 0);
    return;
}

/* Read the entire file by directly reading the file I/O buffer.
 * When the end of the I/O buffer is reached, advance the buffer.
 */
for (dwCount = dwDataSize, hptr = lpData; dwCount  0; dwCount--)
{
    /* Check to see if the I/O buffer must be advanced.
     */
    if (mmioinfo.pchNext == mmioinfo.pchEndRead){
        if(mmioAdvance(hmmio, &mmioinfo, MMIO_READ)){
            Error("Failed to advance buffer.");
            ...
            mmioClose(hmmio, 0);
            return;
        }
    }
   
    /* Get a character from the buffer.
     */
    *hptr++ = *mmioinfo.pchNext++;
}

/* End direct buffer access and close the file.
 */
mmioSetInfo(hmmio, &mmioinfo, 0);
mmioClose(hmmio, 0);