Before using a device, you must initialize it with the open command. The number of devices you can have open depends on the amount of available memory. The syntax for the open command has the following form:
The parameters for the open command are:
Parameters | Description |
device_name | Specifies the destination device or an MCI element (file) name. |
shareable | Allows applications to share a common device or device element. |
type device_type | Specifies the device type when the device_name refers to an MCI element. |
alias alias | Specifies a replacement name for the device. |
MCI classifies device drivers as compound and simple. Compound device drivers use a device element–a media element associated with a device–during operation. For most compound device drivers, the device element is the source or destination data file. For these file elements, the element name references a file and its path. Compound devices include animation devices, waveform audio devices, and MIDI sequencers.
Simple device drivers do not require a device element for playback. Simple devices include CD audio devices and videodisc devices.
Simple devices require only the device_name for operation. You don't need to provide
any additional information (such as a name of a data file) to open these devices. For
these devices, substitute the name of a device type obtained from the [mci] section of SYSTEM.INI for the device_name. For example, you can open a videodisc device with “open videodisc1.”
If you want to open a specific simple device, you can use the filename of the device driver for the device_name. Opening a device with the filename will make an application device dependent and can prevent the application from running if the system configuration changes. When you specify the filename of the device driver, you can optionally include the .DRV extension but do not include the path to the file.
Depending upon your needs, there are three ways you can open a compound device:
By specifying just the device type
By specifying both the element name and the device type
By specifying just the element name
To determine the capabilities of a device, you can open a device by specifying only the device type. When opened this way, most compound devices will only let you determine their capabilities and close them. For example, you can open the sequencer with “open sequencer.”
You can specify the device type either by using the device type from the SYSTEM.INI
file or by using the filename of the device driver. Opening a device with the filename
of the device driver will make an application device dependent and can prevent the application from running if the system configuration changes. If you specify the filename of the device driver, you can optionally include the .DRV extension but do not include the path to the file.
To associate a device element with a particular device, you must specify the element name and device type. In the open command, substitute the element name for the device_name, add the type flag, and substitute the name of the device you want to use for device_type. This combination lets your application specify the MCI device it needs to use. For example, you can open a device element of the waveaudio device with “open train.wav type waveaudio.”
To associate a default MCI device with a device element, you can specify just an element name. In this case, MCI uses the extension of the element name to select the default device from the list in the [mci extensions] section of the SYSTEM.INI file. The entries in the [mci extensions] section use the following form:
file extension = device type
MCI implicitly uses the device type if the extension is found. The following fragment shows a typical [mci extensions] section:
[mci extensions]
wav=waveaudio
mid=sequencer
rmi=sequencer
mmm=mmmovie
With these definitions, MCI opens the default waveaudio device if you use “open train.wav.”
The shareable flag lets multiple applications or tasks access the same device (or element) and device instance concurrently. If your application opens a device or device element without the shareable flag, no other application can access it simultaneously. If your application opens a device or device element as shareable, other applications can also access it by also opening it as shareable. The shared device or device element gives each application the ability to change the parameters governing the operating state of the device or device element. Each time a device or device element is opened as shareable, MCI returns a unique device ID even though the IDs refer to the same instance.
If you make a device or device element shareable, your application should not make any assumptions about the state of a device. When working with shared devices, your application might need to compensate for changes made by other applications using the same services.
If a device can service only one open instance it will fail an open with the shareable flag.
While most compound device elements are not shareable, you can open multiple elements (where each element is unique), or you can open a single element multiple times. If you open a single file element multiple times, MCI creates an independent instance for each of them. Each file element you open this way must have a unique name. The alias flag described in the next section lets you use a unique name for each element.
The alias flag specifies an alternate name for the given device. The alias provides a shorthand notation for compound devices with lengthy pathnames, and it lets you open multiple instances of the same file. If your application creates a device alias, it must use the alias rather than the device name for all subsequent references.
If you wish to create a new device element without specifying an element name, you can specify new as a device_name. MCI does not save a new file element until you save it with the save command. When creating a new file, you must include a device alias with the open command. The following commands open a new waveaudio device element, start and stop recording, save the file element, and close the device element:
open new type waveaudio alias capture
record capture
stop capture
save capture orca.wav
close capture