When a program makes use of the CD-ROM drive, it can be a nice touch to open and close the door under program control.

The technique that allows you to do this relies on the mciSendString function from the Windows API. This function provides a general purpose interface to Windows' multimedia capabilities. This is its declaration:

Because the CD-ROM is considered to be a multimedia device, you can use this API function to control it. The first argument tells the device what you want to do. For example, pass the string "set CDAudio door open" to open the door, like this:

Code:

retval = mciSendString("set CDAudio door open", "", 0, 0)

You can see that the second through the fourth arguments aren't used in this case and are passed either a blank string or the value zero. Likewise, the function's return value can be ignored. Along with the function declaration shown above, you can put the following two procedures in a code module in your program to provide control of the CD-ROM door.

DLL procedures declared in standard modules are public by default and can be called from anywhere in your application. DLL procedures declared in any other type of module are private to that module, and you must identify them as such by preceding the declaration with the Private keyword.