79.3.4 Handling MCI Errors

You should always check the return value of the mciSendCommand function. If it indicates an error, you can use mciGetErrorString to get a textual description of the error. You can also interpret the error code yourself—MMSYSTEM.H defines constants for MCI error return codes.

Note:

To interpret an mciSendCommand error return value yourself, mask the high-order word—the low-order word contains the error code. However, if you pass the error return to mciGetErrorString, you must pass the entire DWORD value.

The following function takes the MCI error code specified by dwError, passes it to mciGetErrorString, and displays the resulting textual error description using MessageBox.

/* Uses mciGetErrorString to get a textual description of an MCI error.

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

}