Skip to content

Latest commit

 

History

History
78 lines (62 loc) · 2.58 KB

File metadata and controls

78 lines (62 loc) · 2.58 KB
title description ms.assetid keywords ms.topic ms.date ms.custom
Accessing a File I/O Buffer
Accessing a File I/O Buffer
b829d8ef-8e0b-4c30-b8cf-e9feccc63bbf
multimedia file I/O,accessing buffers
file I/O,accessing buffers
input and output (I/O),accessing buffers
I/O (input and output),accessing buffers
accessing I/O buffers
buffered I/O
mmioSetInfo function
concept-article
4/26/2023
UpdateFrequency5

Accessing a File I/O Buffer

[The feature associated with this page, Multimedia File I/O, is a legacy feature. It has been superseded by Source Reader. Source Reader has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader instead of Multimedia File I/O, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The following example accesses an I/O buffer directly to read data from a waveform-audio file.

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

// Get information about 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); 

When you finish accessing a file I/O buffer, call the mmioSetInfo function, passing an address of the MMIOINFO structure filled by the mmioGetInfo function. If you wrote to the buffer, set the MMIO_DIRTY flag in the dwFlags member of the MMIOINFO structure before calling mmioSetInfo. Otherwise, the buffer will not be flushed to disk.