Condividi tramite


Accesso a un buffer di I/O file

[La funzionalità associata a questa pagina, I /O file multimediale, è una funzionalità legacy. È stato sostituito dal lettore di origine. Lettore di origine è stato ottimizzato per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi lettore di origine invece di I/O file multimediali, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.

L'esempio seguente accede direttamente a un buffer di I/O per leggere i dati da un file audio waveform.

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); 

Al termine dell'accesso a un buffer di I/O di file, chiamare la funzione mmioSetInfo , passando un indirizzo della struttura MMIOINFOriempita dalla funzione mmioGetInfo . Se è stato scritto nel buffer, impostare il flag MMIO_DIRTY nel membro dwFlags della struttura MMIOINFO prima di chiamare mmioSetInfo. In caso contrario, il buffer non verrà scaricato su disco.