Opening and Closing the CD Tray

Opening and closing the CD tray from your Win32 application is really easy. You just need to include winmm.lib in your code:

INCLUDE C:\masm32\include\winmm.inc
INCLUDELIB C:\masm32\lib\winmm.lib

And then call mciSendString with the command you want to send:

.DATA
sMciOpenTray  DB "set cdaudio door open wait", 0
sMciCloseTray DB "set cdaudio door closed wait", 0

.CODE
; open the CD tray
INVOKE mciSendString, ADDR sMciOpenTray, 0, 0, 0
; close the CD tray
INVOKE mciSendString, ADDR sMciCloseTray, 0, 0, 0

You can see all the possible commands in the MSDN reference for mciSendString.

Here is an example app written in MASM32: cd-tray.zip (sources included, of course).

Comments