Gestione degli errori MCI

[La funzionalità associata a questa pagina, MCI, è una funzionalità legacy. È stato sostituito da MediaPlayer. MediaPlayer è stato ottimizzato per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi MediaPlayer invece di MCI, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.

È consigliabile controllare sempre il valore restituito della funzione mciSendCommand . Se indica un errore, è possibile usare mciGetErrorString per ottenere una descrizione testuale dell'errore.

Nell'esempio seguente viene passato il codice di errore MCI specificato da dwError a mciGetErrorString e quindi viene visualizzata la descrizione dell'errore testuale risultante usando la funzione 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);
    }
}
 

Nota

Per interpretare manualmente un valore restituito di errore mciSendCommand , mascherare la parola di ordine elevato (la parola con ordine basso contiene il codice di errore). Se si passa il valore restituito dell'errore a mciGetErrorString, tuttavia, è necessario passare l'intero valore doubleword.