Sending Command Strings Using mciSendString

You use the mciSendString function to send command strings to a device. It has the following syntax:

WORD FAR PASCAL mciSendString(lpstrCommand, lpstrRtnString, wRtnLength, hCallback)

The far pointer lpstrCommand points to the a null-terminated string that specifies the MCI control command. The string has the following form:

command device_name arguments

The second parameter, lpstrRtnString, points to an application-supplied buffer for a return string. The third parameter, wRtnLength, specifies the size of this buffer. If an MCI command returns a value or a string, MCI copies it into lpstrRtnString as a null-terminated string (integers are converted to strings). If the length of the return string exceeds the size of the buffer, MCI returns an error. You can assign NULL to lpstrRtnString if you don't want the return string, or for commands that don't supply return information.

The last parameter, hCallback, is a handle to the window that receives the MM_MCINOTIFY message. MCI ignores this parameter unless the command contains the notify flag. This parameter must contain a valid window handle if the notify flag is used.

The following statement passes the “play to 500” command string to a videodisc device driver:

dwErrorCode = mciSendString ("play videodisc1 to 500", NULL, 0, 0L);

The mciSendString function returns zero if successful. If the function fails, it returns an error code. If there is an error, you can get a description of it by passing the error code to mciGetErrorString.

The MCITEST application contains examples of using mciSendString and mciGetErrorString. You can use this application to experiment with MCI devices and command strings.