CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Open CD-Rom

  1. #1
    Guest

    Open CD-Rom

    How can I open a CD-Rom device by software ?

    Thanks for help !

    Michael


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Open CD-Rom

    Try the following code in a module / form / class / etc...


    '
    ' Change public to private as appropriate
    '
    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
    '
    public Sub EjectCD()
    Call mciSendString("set CDAudio Door Open Wait", 0&, 0&, 0&)
    End Sub
    '
    public Sub CloseCD()
    Call mciSendString("set CDAudio Door Close Wait", 0&, 0&, 0&)
    End Sub




    - I don't have a CD on this machine here, but it used to work fine.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  3. #3
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Open CD-Rom

    This is good code, but I couldn't it to close the Cd tray. it opened just fine. I'm running NT 4 workstation, any suggestions.

    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  4. #4
    Join Date
    Jan 2000
    Location
    Kansas City, MO
    Posts
    34

    Re: Open CD-Rom

    '
    ' Change public to private as appropriate
    '
    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
    '
    Public Sub EjectCD()
    Call mciSendString("set CDAudio Door Open", 0&, 0&, 0&)
    End Sub
    '
    Public Sub CloseCD()
    Call mciSendString("set cdAudio Door Closed", 0&, 0&, 1&)
    End Sub

    You'll notice, all I did was take out the waits ( It will probably work with them in though) and changed the last parameter from 0& to 1&, Presto! closing cdrom door!

    Old school... six lines a day and I'm done.

  5. #5
    Join Date
    Jan 2000
    Location
    Kansas City, MO
    Posts
    34

    Re: Open CD-Rom

    I'm an idiot!!!
    In Chris Eastwoods example everything was exactly correct, except, his close string was "set CDAudio Door Close Wait" it should have been "set CDAudio Door Closed Wait"
    That is the only change that needs to be made, no 0's to 1's or none of that crap. I'm just an idiot! ......(walks off mumbling shaking head) :-)

    Old school... six lines a day and I'm done.

  6. #6
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Open CD-Rom

    Thank you! That was it, add the "d" to "close".

    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured