77.2.3 Sending Command Messages

Windows provides the following functions to send command messages to devices and to query devices for error information:

Function Description

mciSendCommand Sends a command message to an MCI device.
mciGetErrorString Returns the error string corresponding to an error number.

77.2.3.1 The MCI Device ID

MCI returns a device ID when you open a device using the MCI_OPEN command. Use this ID to identify the opened device when sending subsequent commands.

MMSYSTEM.H defines a special constant, MCI_ALL_DEVICE_ID, to indicate that a command be sent to all of the MCI devices that an application has opened. You can use MCI_ALL_DEVICE_ID with any command that does not return information. For example, the following code fragment closes all of the MCI devices that are opened by an application:

UINT wDeviceID;

DWORD dwReturn;

/* Closes all MCI devices opened by this application.

* Waits until devices are closed before returning.

*/

if (dwReturn = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE,

MCI_WAIT, NULL))

/* Error, unable to close all devices

*/

...

Note:

While using the MCI_ALL_DEVICE_ID identifier is a convenient way to broadcast a command to all your devices, don't rely on it to synchronize devices; the timing between messages can vary.