Sending Command Messages

You use mciSendCommand to send command messages to MCI devices. This function has the following syntax:

DWORD mciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2)

The WORD wDeviceID identifies the MCI device that receives the message wMessage and associated data dwParam1 and dwParam2. The dwParam1 DWORD specifies the flags for the message and the dwParam2 DWORD specifies a pointer to the message data structure.

MCI command messages use the flags in dwParam1 for two purposes: to request options, and to indicate which fields of the corresponding data structure contain data. If data is associated with a flag, remember to assign the data to the appropriate data field of the data structure as well as set the dwParam1 flag. If you don't need to use the data structure to send any information to the device, you can use NULL for the pointer to the data structure.

MCI creates a device identifier when you open a device using the MCI_OPEN message. (When sending an open message, you can set wDeviceID to NULL.) After the device is open, obtain the device identifier from the wDeviceID field of the MCI_OPEN_PARMS data structure. Retain this value for use with subsequent MCI commands. You can also determine wDeviceID by calling mciGetDeviceID. (The argument for mciGetDeviceID is the device name, which can be the device element name, the device alias, or the device type used to register the device.)

You can use MCI_ALL_DEVICE_ID as wDeviceID for any message that does not return information. When you specify MCI_ALL_DEVICE_ID, all devices opened by the current task receive the command. For example, sending MCI_CLOSE with this ID closes all open devices, and sending MCI_PLAY1 with it starts playback of all devices opened by the task. While this ID is convenient to send a message to all your devices, don't rely on it to synchro-nize devices; the timing between messages can vary.

The mciSendCommand function returns zero if successful. If the function fails, the low-order word of the return value contains an error code. You can send this error code to mciGetErrorString to get a text description of it.