|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic Disk/Drive API Routines mciSendString: Ejecting Media from a CD-ROM |
||
Posted: | Sunday June 21, 1998 | |
Updated: | Monday December 26, 2011 | |
Applies to: | VB4-32, VB5, VB6 | |
Developed with: | VB5, Windows 98 | |
OS restrictions: | None | |
Author: | VBnet - Randy Birch | |
Related: |
GetDriveType: Identify a System's CD-ROM Drive DeviceIoControl: Load/Eject Removable Media DeviceIoControl: Lock/Unlock Removable Media Devices |
|
Prerequisites | |||||||||||||||||||||
None. | |||||||||||||||||||||
|
|||||||||||||||||||||
The Multimedia functions provide several commands via the mciSendString API. Perhaps one of the most frequently requested is ejecting (and loading) a CD automatically from code. Using a single line call, this is easily achieved. | |||||||||||||||||||||
BAS Module Code | |||||||||||||||||||||
None. | |||||||||||||||||||||
|
|||||||||||||||||||||
Form Code | |||||||||||||||||||||
Drop a command button onto a form and add the following: | |||||||||||||||||||||
|
|||||||||||||||||||||
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Declare Function mciSendString Lib "winmm.dll" _ Alias "mciSendStringA" _ (ByVal lpstrCommand As String, _ ByVal lpstrReturnString As String, _ ByVal uReturnLength As Long, _ ByVal hwndCallback As Long) As Long Private Sub Command1_Click() Call mciSendString("Set CDAudio Door Open Wait", 0&, 0&, 0&) End Sub |
|||||||||||||||||||||
Comments | |||||||||||||||||||||
Pretty simple -- the API takes a pre-defined string and
executes it. The return value is 0 if successful, or an error code if not. And unlike its sister the mciSendCommand api, there is no
need to obtain a handle to the device. However, on systems with multiple CD-ROMs installed, this may be the only method to assure the correct
CD is ejected. But since I have only one here, I can't test this out.
The following table, from the MSDN reference, lists device types that recognize the set command and the flags used by each type:
|
|||||||||||||||||||||
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |