處理 MCI 錯誤

[與此頁面 MCI相關聯的功能是舊版功能。 MediaPlayer已取代它。 MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用 MediaPlayer 而非 MCI。 Microsoft 建議使用舊版 API 的現有程式碼盡可能重寫為使用新的 API。

您應該一律檢查 mciSendCommand 函式的傳回值。 如果指出錯誤,您可以使用 mciGetErrorString 來取得錯誤的文字描述。

下列範例會將 dwError 指定的 MCI 錯誤碼傳遞至 mciGetErrorString,然後使用 MessageBox 函式顯示產生的文字錯誤描述。

// Use mciGetErrorString to get a textual description of an MCI error.
// Display the error description using MessageBox.

void showError(DWORD dwError)
{
    char szErrorBuf[MAXERRORLENGTH];
    MessageBeep(MB_ICONEXCLAMATION);
    if(mciGetErrorString(dwError, (LPSTR) szErrorBuf, MAXERRORLENGTH))
    {
        MessageBox(hMainWnd, szErrorBuf, "MCI Error",
        MB_ICONEXCLAMATION);
    }
    else
    {
        MessageBox(hMainWnd, "Unknown Error", "MCI Error",
            MB_ICONEXCLAMATION);
    }
}
 

注意

若要自行解譯 mciSendCommand 錯誤傳回值,請遮罩低序字 (包含錯誤碼) 。 不過,如果您將錯誤傳回值傳遞至 mciGetErrorString,則必須傳遞整個雙字值。