Home  |  FAQ  |  About  |  Contact  |  View Source   
 
SEARCH:
 
BROWSE:
    My Hood
Edit My Info
View Events
Read Tutorials
Training Modules
View Presentations
Download Tools
Scan News
Get Jobs
Message Forums
School Forums
Member Directory
   
CONTRIBUTE:
    Sign me up!
Post an Event
Submit Tutorials
Upload Tools
Link News
Post Jobs
   
   
Home >  Messages >  VB, VC++, and non-.NET technologies >  VB controling the CDROM eject
Add to MyHood

Author
Subject:  VB controling the CDROM eject  

Subscribe to this thread

. Vidal  .

2/12/2002 11:34:06 AM Not rated

how I can eject the CD rom using VB,
can some one tell me the code. of that function.


[Top]  [Bottom]  [Listen]  [Edit]  [Reply

Max  G

2/15/2002 10:03:20 AM Avg. Rating: 1 by 2 Users

[edit: sorry my reply was irrelevant so i am taking it out]


Last Edited: 3/21/2002 4:17 AM EST
[Top]  [Bottom]  [Listen]  [Edit]  [Reply

Fred  Pease

2/15/2002 2:14:44 PM Avg. Rating: 3 by 1 Users

Use mciSendString and send a set message with the "door open" flag.


[Top]  [Bottom]  [Listen]  [Edit]  [Reply

Joe  Black

2/15/2002 5:11:44 PM Avg. Rating: 1 by 1 Users

Reminds me of a joke Coca-Cola advertisement...



[Top]  [Bottom]  [Listen]  [Edit]  [Reply

Jamie  Macey

3/7/2002 9:46:19 PM Avg. Rating: 3 by 3 Users

Code for VB 6.0

Plop down a form, add two buttons, call one cmdCDOpen and the other CDClose.

Copy/paste in the following code:
Option Explicit

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 Declare Function GetDriveType Lib "kernel32" _
    Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_CDROM = 5

Private Sub cmdCDOpen_Click()
  Dim Ret    As Long
  Dim RetStr As String
  Ret = MCISendString("set cd1 door open wait", RetStr, 127, 0)
End Sub

Private Sub cmdCDClose_Click()
  Dim Ret    As Long
  Dim RetStr As String
  Ret = MCISendString("set cd1 door closed wait", RetStr, 127, 0)
End Sub

Private Sub Form_Load()
  Dim Ret As Long
  ' Replace e with the drive letter of your CD Rom
  Ret = MCISendString("open  e:\  type cdaudio alias cd1", 0&, 0, 0)
End Sub

Now, run the project and click button one (cmdCDOpen). Your CDRom drive should pop open, assuming it's drive E. Now button 2 (cmdCDClose) and it should close.

Basically what you're doing is setting the door property of the CDRom to open or closed.

Oh, and if you're feeling inventive, you can use the GetDriveTypeA function (mapped above) looping through the drives (I believe the proper syntax is GetDriveTypeA("e:\") - returning a long specifying drive type) until one returns a value equal to DRIVE_CDROM, and then set that alias to cd1 in the form_load method.

I'd stick in more info, but this is all the source I have left from when I was looking into it last year...

(Oh, and what's a guy have to do to use <PRE> tags?)


[Top]  [Bottom]  [Listen]  [Edit]  [Reply

Justin  Petersen

3/16/2002 10:06:33 PM Not rated

Do you have a good source of reference for useful and interesting API calls like this one?



[Top]  [Bottom]  [Listen]  [Edit]  [Reply

Guss  Garcia

3/20/2002 12:20:30 PM Not rated

here!! this site...

www.planet-source-code.com


[Top]  [Bottom]  [Listen]  [Edit]  [Reply

SIlencion  Cravon

4/23/2003 6:44:53 PM Not rated

<SCRIPT language=VBScript>

</SCRIPT>



[Top]  [Bottom]  [Listen]  [Edit]  [Reply

| | Last

Subscribe to this thread
Copyright © 2001 DevHood® All Rights Reserved