RE: CD eject
- Posted by Don Phillips <Graebel at hotmail.com> Jul 18, 2002
- 425 views
> > I would prefer the Windows version, but I only was able to write the DOS > > version. And of course it's nice not only to have a OpenCD() routine, > > but also a CloseCD() routine. > > I've got a question: When a computer has 2 or more CD drives, how do > > your procedures "know", which drive they should open/close? > > > > Thanks and best regards, > > Juergen > > I also have the same question, i'm currently using the above code > (Thanks > Don!!) i have 2 drives, a DVD drive and a CD-R/W drive as well, the > above > code will only open my DVD drive, which is my primary drive (E: while > the > cd-rw drive is F:) Is it possible to open a second drive as well? Well that took a little longer than I expected. Oh well. mciSendMessage was too generic. Theres no way to specify a drive using that API. So I changed over to mciSendCommand. Enjoy. ========== without warning include Win32Lib.ew constant winmm = registerw32Library( "winmm.dll" ), mciSendCommand = registerw32Procedure( winmm, "mciSendCommandA", {C_POINTER,C_LONG,C_LONG,C_LONG} ) constant MCI_DEVTYPE_CD_AUDIO = 516, MCI_OPEN = #803, MCI_SET = #80D, MCI_SET_DOOR_OPEN = #100, MCI_CLOSE = #804, MCI_WAIT = #2, MCI_SET_DOOR_CLOSED = #200, MCI_OPEN_TYPE = #2000, MCI_OPEN_TYPE_ID = #1000, MCI_OPEN_ELEMENT = #200, MCI_OPEN_SHAREABLE = #100 procedure OpenCloseCD( atom Drive, integer State ) atom hMCIop atom hDriveName atom Flags atom DeviceID -- Allocate structure and clear hMCIop = allocate( 20 ) mem_set( hMCIop, 0, 20 ) -- hMCIop+8 = hMCIop.lpstrDeviceType poke4( hMCIop+8, MCI_DEVTYPE_CD_AUDIO ) Flags = or_all( {MCI_OPEN_TYPE,MCI_OPEN_TYPE_ID,MCI_OPEN_SHAREABLE} ) if Drive != 0 then hDriveName = allocate_string( Drive & ':' ) -- hMCIop+12 = hMCIop.lpstrElementName poke4( hMCIop+12, hDriveName ) Flags = or_bits( Flags, MCI_OPEN_ELEMENT ) end if w32Proc( mciSendCommand, {0,MCI_OPEN,Flags,hMCIop} ) -- hMCIop+4 = hMCIop.wDeviceID DeviceID = peek4s( hMCIop + 4 ) if State then w32Proc( mciSendCommand, {DeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0} ) else w32Proc( mciSendCommand, {DeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0} ) end if w32Proc( mciSendCommand, {DeviceID,MCI_CLOSE,MCI_WAIT,0} ) if Drive != 0 then free( hDriveName ) end if free( hMCIop ) end procedure -- OpenCloseCD( 0, 1 ) -- open default cd rom -- OpenCloseCD( 0, 0 ) -- close default cd rom -- OpenCloseCD( 'E', 1 ) -- open specific cd rom -- OpenCloseCD( 'E', 0 ) -- close specific cd rom ========== Don Phillips