1. RE: CD eject
- Posted by Don Phillips <Graebel at hotmail.com> Jul 15, 2002
- 451 views
> I'm wondering if anyone has a code (windows) that will access a CD-ROM > drive and make it eject.? Thanks! > I saw Juergen Luethje's code snip for ejecting a CD using INTs. Very interesting. If however you would prefer the Windows version of the same, use this: ========== include Win32Lib.ew constant winmm = registerw32Library( "winmm.dll" ) constant mciSendString = registerw32Procedure( winmm, "mciSendStringA", {C_POINTER,C_POINTER,C_POINTER,C_POINTER} ) procedure OpenCD() atom OpenStr OpenStr = allocate_string( "Set cdaudio door open wait" ) w32Proc( mciSendString, {OpenStr, 0, 0, 0} ) free( OpenStr ) end procedure procedure CloseCD() atom CloseStr CloseStr = allocate_string( "Set cdaudio door closed wait" ) w32Proc( mciSendString, {CloseStr, 0, 0, 0} ) free( CloseStr ) end procedure ========== Don Phillips
2. 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 Well all of my computers only have one, so I cant really test it for this case. However following standards, I would assume that it would open the first available. I bet that if I poked at the routines a little I can remove this restriction. I do know of several APIs to check what kind of drive is at a given location. I am not at my dev machine atm, I will look at it when I am able... Don
3. RE: CD eject
- Posted by Don Phillips <Graebel at hotmail.com> Jul 18, 2002
- 426 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