共用方式為


存取檔案 I/O 緩衝區

[與此頁面相關聯的功能 多媒體檔案 I/O是舊版功能。 來源讀取器已取代它。 來源讀取器已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用 來源讀取器 ,而不是 多媒體檔案 I/O。 Microsoft 建議使用舊版 API 的現有程式碼盡可能重寫為使用新的 API。

下列範例會直接存取 I/O 緩衝區,以讀取來自電壓音訊檔案的資料。

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

當您完成存取檔案 I/O 緩衝區時,請呼叫mmioSetInfo函式,傳遞mmioGetInfo函式所填入之 MMIOINFO結構的位址。 如果您寫入緩衝區,請先在MMIOINFO結構的dwFlags成員中設定MMIO_DIRTY旗標,再呼叫mmioSetInfo。 否則,緩衝區將不會排清到磁片。