Open sesame, CD-ROM!

 

Summary

When your program makes use of the CD-ROM drive, it can be a nice touch to open and close the door under program control. Here's a VB tip on how you can open the CD-ROM door.

Events

IBM Technology Conference & Expo 2012
May 23, 2012

Convention Centre B2 Room at 22nd Floor, Centara Grand @ Central World, 999/99 Rama I Road, Pathumwan, Bangkok 10330

Echelon 2012
June 11 and 12, 2012

University Cultural Centre, National University of Singapore

Startup Asia Jakarta 2012
June 7 and 8, 2012

12th Floor, Annex Building, Wisma Nusantara Complex, Jl. M.H. Thamrin No. 59 Jakarta 10350, Indonesia

MMA Forum Singapore
April 23-25, 2012

Grand Hyatt Singapore

When your program makes use of the CD-ROM drive, it can be a nice touch to open and close the door under program control. We'll show you how in this article.

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:

Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
  (ByVal lpCommandString As String, ByVal lpReturnString As String, _
  ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

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:

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.

Public Sub OpenCDDoor()

Dim retval As Long

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

End Sub
Public Sub CloseCDDoor()

Dim retval As Long

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

End Sub

Note that calling OpenCDDoor when the door is already open, or CloseCDDoor when it is closed, has no effect.

Talkback

Add your opinion

In order to post a comment, you need to be registered. (Sign In or register below)

Post your comment

ZDNet Asia Live

RT @zdnetasia: Homegrown smartphone OSes gaining favor in China. http://t.co/lL8KbccW

Big data acquisitions pave way to fast, effective innovation - ZDNet Asia http://t.co/ky8YgPAn #Bigdata #analytics via @ciropuglisi

Big data acquisitions pave way to fast, effective innovation - ZDNet Asia: Big data acquisition... http://t.co/r6taCmG1 #ITNews #BigData

Big data acquisitions pave way to fast, effective innovation - Zd Net http://t.co/d9k21ro5: David G... http://t.co/4JgaOz8g #bigdata #sna

Big data acquisitions pave way to fast, effective innovation - Zd Net http://t.co/fbori8UQ: Incr... http://t.co/nuEeUbj7 #ITNews #BigData

Big data acquisitions pave way to fast, effective innovation - ZDNet Asia http://t.co/iFQ74xYI #Bigdata #analytics

@ChemarieMonica : Integration, focused investments to propel Windows Phone - ZDNet As... http://t.co/ZVPDpbxH http://t.co/1QrdIsaV #tech

China social media companies have global potential
http://t.co/p8fkRbfD Chinese social media companies such as #Renren and #Sina might...

China social media companies have global potential
http://t.co/Y3x1qBI1 Chinese social media companies such as #Renren and #Sina might...

#radio Radio United Kingdom by EnjoyIT 1.0 http://t.co/YoV1dcFJ

#radio Radio United Kingdom by EnjoyIT 1.0 http://t.co/CbzcXPPO

Integration, focused investments to propel Windows Phone - ZDNet Asia: Gadget Helpline (blo... http://t.co/JZwEJCen http://t.co/KpTZdvuO

'Scramble' among vendors to acquire #bigdata co.s to bolster product offerings, manpower and market position. http://t.co/YWjgqj4r #in

Homegrown smartphone OSes gaining favor in China thanks to integration with local online services: IDC http://t.co/PJFx58yp #in

Companies see sustainability as critical for future biz growth, but face low margins in short term: study. http://t.co/I7jI8uix #in

So much as we know , MTK6575 extremely integrated frequency1GHz ARM Cortex-A9 processor, the superiority of 3G / HSPA Modem, and help the...

1 day ago by y15822137359 on 5 SaaS adoption speed bumps to avoid

I reckon your view: "CRM is strategy, not software", if a company replicating the approach uses in ERP implementation into CRM, what they...

2 days ago by wykoong on Gartner: Mobile CRM gives better ROI than social

This video will teach you about the Excel fill handle but also provide you with a workook to download... http://www.youtube.com/watch?v=...

3 days ago by TradeBrother on A quick fill handle trick for Microsoft Excel

waiting...

5 days ago by eapete on What should count in a company's market value?

Boy, you've opened a can of worms now.

Wait for the rants & raves.

5 days ago by eapete on What should count in a company's market value?

I was puzzling before this whether to replicate the success formula we executed for a financial institute, and come out with a standard s...

5 days ago by wykoong on Drop the egos, copy ideas, then innovate