Problem in accessing cd drives

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
96
Programming Experience
Beginner
Hi friends,
I hav got two problems while accessing cd drives.

FIRSTLY: I want a code example of how to detect whether the cd drive of my machine is opened or closed.

SECONDLY: I'm trying to open or close the cd drive of my machine. It's working properly if there's only one cd drive. But wut if there r more than one. The code I'm using is accessing the default cd drive only. Below is the code I'm using:

'In the general declarations:
'----------------------------------------
Option Explicit

Private Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
pstrReturnString As String, ByVal uReturnLength As Long, ByVal _
wndCallback As Long) As Long


'The procedure that performs the cd drive door open/close operation
'-------------------------------------------------------------------------------------------------
Public Sub OpenOrShutCDDrive(DoorOpen As Boolean)

Dim lRet As Long

If DoorOpen Then
lRet = mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
lRet = mciSendString("Set CDAudio door closed", 0&, 0&, 0)
End If

'lRet will = 0 upon success, so if you want to make this
'a function, return true if lret = 0, false otherwise

End Sub



'In Button1_click event:
'-----------------------------------
'Parameter for calling the following procedure will be true or false
Call OpenOrShutCDDrive(True)

Now, how can I open/close the cd drive of my choice? Should I have to provide the path name of the drive then how to do it? Plz help.
 
Found some samples where they did this: "Open E: Alias LaufwerkE Type CDAudio", "Set LaufwerkE Door Open" Try it.
 
Thanx I managed to make it work somehow.
But, can U help me someway to identify whether the cd drive door is opened or not. Because, based on that I'll have to pass the argument (True/False) to the procedure OpenOrShutCDDrive(DoorOpen As Boolean). If it's opened then the argument should be false(close the door), else true(open the door).
 
Is it a problem if you click "close" button if the drive is already closed? or the "open" button if the drive is already open?
 
Yeah U r write. In case of using two separate buttons also, U'll be calling the same procedure and pass the argument (true/false). So, if U don't know the current status of the cd door, how'll U decide whether to send true or false. There's where the problem is. Can somebody focus on this point?
 
I was going to say that I'm not sure that it is possible, but then I had a play with right-clicking the drive in My Computer and pressing Eject, and it doesn't close when you press Eject if it is already open, which implies that there is some way of either detecting the status, or sending a command to specifically open as opposed to open/close. Of course, I'm not sure whether there is a way of sending a specific close instruction - it might be an asymmetric API.

I doubt very much that there is anything in the .NET framework to do it, so we're probably looking at WIN32 API. I'll have a look around and see if I can find anything.
 
I have an answer for you now on my blog. I've just tried it and it won't open if you say close or close if you say open.
 
Problem in accessing CD Drive

I've seen the bit of code in ur blog. As I can see U hav used two commands “set cdaudio door open” and “set cdaudio door
closed”. If U look into the code that I hav posted in the beggining U can see that I hav used the same commands also. I can manage upto that. But what I wanna know is that how'll U decide which command to use, provided that I am using a single button to Open/Close. For that I am passing the arguments True or False and inside the procedure I'm checking the condition whether the argument supplied is True or False and using the commands respectively. The CD door will act accordingly.

But this is not automated as I'm manually checking and passing the arguments (see in Button1_Click event). This is what I wanna make dynamic. I'm looking for some command that'll automatically check whether the door is opened or not, return TRUE or FALSE and pass them as arguments accordingly. I don't have any problem in opening or closing the door of the drive of my choice. But I need help in identifying the status of cd door. Looking forward for Ur suggestion....
 
Oh sorry, I misread your post. I thought that you had a function for opening or closing and you didn't know which it was going to do. I'm not sure it is actually possible to detect it unless there is a disc in the drive, in which case you would be able to check you can access the file system (I doubt that is the answer you wanted).
 
Problem in accessing CD Drives

Hi everyone, I'm focusing on a real tough problem that I hav been trying to solve since a long time. I'm trying to detect the Open or close status of the Cd drive door. I'm using mcisendstring function to query the status, mcisendstring("Status CDAudio Mode"). This function returns the following values accordingly:
"not ready", "paused", "playing", and "stopped" values.

Some devices can return the additional "open", "parked", "recording", and "seeking" values.

If there is a cd in the drive and the door is closed then it's almost easy to identify as "status CDAudio mode" returns a value anything other than "open". But the real problem is when the CD door is open the value returned by the mcisendstring function is "open". Again when the CD door is closed with no CD inside the function is returning the same value "open". There's no way I can distinguish the CD tray status programatically when the value returned is "open". Can anybody help me? Is there any other way other than the mcisendstring function to query the CD door status? If yes then Plz provide me a code example.
 
Last edited by a moderator:
Back
Top