MciSendCommand
Appearance
This function sends a media control interface message to the specified media device.
Syntax
mciSendCommand(usDeviceID, usMessage, ulParam1, pParam2, usUserParm)
Parameters
- usDeviceID (USHORT) - input
- The device ID the message is to be sent to. This is the device ID returned from MCI_OPEN; this parameter is ignored on the MCI_OPEN message.
- usMessage (USHORT) - input
- The media control interface message to send. See MCI Command Messages for descriptions of these messages.
- ulParam1 (ULONG) - input
- Flags for this message. These flags are defined separately for each message; however, the following flags are available for all media control interface messages unless denoted in the message description. MCI_NOTIFY and MCI_WAIT are mutually exclusive.
- MCI_NOTIFY
- A notification message (MM_MCINOTIFY) will be posted to the window specified in the hwndCallback parameter of the data structure pointed to by the pParam2 parameter. The notification will be posted when the action indicated by this message is completed or when an error occurs.
- MCI_WAIT
- Control is not returned until the action indicated by this message is completed or an error occurs.
- pParam2 (PVOID) - input
- Pointer to a data structure for this message. These structures are defined separately for each message.
- usUserParm (USHORT) - input
- User parameter returned in the notification for this message.
Return Code
- rc (ULONG) - returns
- Returns MCIERR_SUCCESS in the low-order word if there was no error; otherwise it returns the error code in the low-order word of the return value.
- Use mciGetErrorString to convert this code to a textual string. If the return code is a device-dependent error, the high-order word will contain the device ID. See Return Codes for a listing of possible return values. If the MCI_NOTIFY flag is specified then the device receiving this message performs error checking to see if it can begin processing the message. The amount of required error checking varies depending on the message and device. The device returns to the application and the rest of the command processing occurs asynchronously.
Remarks
Use mciSendString to send textual command strings. The mciSendString function calls an internal string parser to parse the string and sends the resulting structure to mciSendCommand.
Example Code
Declaration:
#define INCL_MCIOS2
#include <os2.h>
USHORT usDeviceID; /* Device ID. */
USHORT usMessage; /* Message action. */
ULONG ulParam1; /* Message flags. */
PVOID pParam2; /* Message data. */
USHORT usUserParm; /* User-specified parameter. */
ULONG rc; /* Return code. */
rc = mciSendCommand(usDeviceID, usMessage,
ulParam1, pParam2, usUserParm);
The following code illustrates how to send a command to a specified device.
MCI_OPEN_PARMS mciOpenParameters;
MCI_PLAY_PARMS mciPlayParameters;
CHAR DeviceType[] = "cdaudio";
/* Device type "cdaudio" */
mciPlayParameters.hwndCallback = PM_Win_Handle;
/* Assign hwndCallback the handle
to the PM Window routine */
mciOpenParameters.pszDeviceType = (PSZ)&DeviceType;
mciSendCommand(
0, /* Don't know the device yet */
MCI_OPEN, /* MCI message */
MCI_WAIT | MCI_OPEN_TYPE_ID, /* Flags for the MCI
message */
(PVOID) &mciOpenParameters, /* Parameters for the message */
0 ); /* No notify message */
mciSendCommand(
mciOpenParameters.usDeviceID, /* Device to play the cdaudio */
MCI_PLAY, /* MCI message */
MCI_WAIT, /* Flags for the MCI message */
(PVOID) &mciPlayParameters, /* Parameters for the message */
0); /* No notify message */
mciSendCommand(
mciOpenParameters.usDeviceID, /* Device to play the cdaudio */
MCI_CLOSE, /* MCI message */
MCI_WAIT, /* Flags for the MCI message */
(PVOID) NULL, /* No Parameter list */
0); /* No notify message */