Solved

Drive Letter of CDROM Drive?

Posted on 1997-04-10
11
377 Views
Last Modified: 2013-12-03
How does the Microsoft open CDROMs based on their Drive letter? I need to determine how to open CDROMs based on drive letters like the built-in CDPlayer in Win95. Any Ideas?

Let's say my system has two CDROMs F: and G:. Now I want my program to detect two cdroms and give the user the ability to open either or both at the same time.  

Whatever code segment is developed should allow me to Open the appropriate drive with mciSendCommand "Open".

I prefer Delphi V1.0 (Pascal) source, but can use and read C, Visual Basic, or ASM.

Also, I need information on Win3.x, but will accept Win32 API calls if there isn't a workaround for Win3.x.
 
Thanks,
John
0
Comment
Question by:zitt
  • 6
  • 4
11 Comments
 

Expert Comment

by:jenga
ID: 1334524
Not quite sure what you mean by open but you can
determine the drive letter of CD-ROMs (there may well
be more than one in a system) by getting the drive type
of each drive A-Z

The Win32 call GetDriveType() returns the drive type of
the requested drive where the requested drive is a string
such as "D:\". For example here is general IsCDRom()
C routine with comments to make your life a little easier.

BOOL IsCDRom(char cDriveLetter)
{
    // Should validate cDriveLetter but ignore for this example!
    // Assume it a letter in the range A-Z for now.
    // Build a string containing the queried drive letter...
    char *szRootDir = "A:\\";
    szRootDir[0] = cDriveLetter;

    // Test if the drive is a CDROM
    return GetDriveType(szRootDir) == DRIVE_CD_ROM;
}

GetDriveType() returns a whole range of drive types not
just CDROM drives (e.g. floppy, network, hard and ramdrive)

Determining whether a drive is a CDROM in Win16 is not
easy. Sorry, but I can't help you there. Also I can't help
you out as far as Pascal is concerned.




0
 

Author Comment

by:zitt
ID: 1334525
Edited text of question
0
 

Author Comment

by:zitt
ID: 1334526
Jenga... you did good based on my original question, but it wasn't what I was looking for. It's really my fault for bein to brief. The only reason for the F:Poor rating was to get additional input on my question.

Please revisit this question.
John
0
 

Accepted Solution

by:
phuene earned 150 total points
ID: 1334527
Hello:
This is win32 api.  I'm not sure if this is the right way to do this for you, but this is what I did.  I've never used mci commands before, but this seems to work on opening my one drive on my local machine.  I hope you can read this, cause its hard to format it for such a small edit box.  Here's the code , hope it helps,
              Regards, PHUENE.

void OpenCDRomDrives()
{
    DWORD Drives;
    MCI_OPEN_PARMS openparams;
    int x=0;
    char *Drive="A:\\";
    Drives=GetLogicalDrives();
    while (x<=25)
    {
        if ( (Drives & (1<<x)) != 0 )
        {
            switch(x)
            {
                case 0:
                Drive[0]='A';
                break;

                case 1:
                Drive[0]='B';
                break;
     
                case 2:
                Drive[0]='C';
                break;
               
                case 3:
                Drive[0]='D';
                break;
       
                case 4:
                Drive[0]='E';
                break;
       
                case 5:
                Drive[0]='F';
                break;
   
                case 6:
                Drive[0]='G';
                break;
                //Etc, you get the point.
            }
            if (GetDriveType(Drive)==DRIVE_CDROM)
            {
                Drive[2]='\0';
                openparams.lpstrDeviceType=(char*)MCI_DEVTYPE_CD_AUDIO;
                openparams.lpstrElementName=Drive;
                if (mciSendCommand(0, MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE, (DWORD)&openparams) == 0)
                {
                    mciSendCommand(openparams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
                    mciSendCommand(openparams.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);
                    MessageBox(NULL,"Opening door",Drive,MB_OK);
                }
                else
                {
                    MessageBox(NULL,"Error opening door",Drive,MB_OK);
                }
            }
        }
        x++;
    }
}

0
 

Author Comment

by:zitt
ID: 1334528
Edited text of question
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:zitt
ID: 1334529
Phuene,

Thanks for the answer... it will take some time to understand and convert the C code to Delphi.

Could you please provide addtional comments? Esp on how MCICOMMAND can receive a "drive" in element?

John
0
 

Expert Comment

by:phuene
ID: 1334530
I'm not 100% sure if the element parameter part is correct, but according to my documents, element is a path, so I experimented a little bit and tried "D:" for the element (my cdrom drive) and it opened, and tried "C:" (main hard drive) and it didn't.  The rest of the mci commands i left the same.  GetLogicalDrives() retrieves a bitmask representing ALL logical drives shown in the windows OS enviroment.  The switch tells us which drives are real, and then GetDriveType() tests if it is a CDROM drive.  If it is, a MCI_OPEN_PARMS structure is filled out with device type and element.  Then a MCI_OPEN message is sent to open the device, then a MCI_SET, with a MCI_SET_DOOR_OPEN parameter.  Then the device is closed with MCI_CLOSE.  Again, this code doesn't check to see the current status of the cdrom drive (opened or not), but i didn't think you needed that.  I'm not sure if this code will work for you, since I only learned it today (researched it for about an hour till i got my cdrom drive door to open).  On a related note, if you are a PC Magizine subscriber, you can obtain a Delphi source of how to open a cd-rom drive door (this is the source i converted to C, this code did not use the element parameter, so i was unsure of how to tell the mci command which drive) from www.pcmag.com. I think it was in the 1997 march issue, not sure the title.  It was about cdrom drives in an "ask our experts" section i believe.  I hope this all explains it better, and further helps your code.  Regards,
                       PHUENE
0
 

Expert Comment

by:phuene
ID: 1334531
I'm not 100% sure if the element parameter part is correct, but according to my documents, element is a path, so I experimented a little bit and tried "D:" for the element (my cdrom drive) and it opened, and tried "C:" (main hard drive) and it didn't.  The rest of the mci commands i left the same.  GetLogicalDrives() retrieves a bitmask representing ALL logical drives shown in the windows OS enviroment.  The switch tells us which drives are real, and then GetDriveType() tests if it is a CDROM drive.  If it is, a MCI_OPEN_PARMS structure is filled out with device type and element.  Then a MCI_OPEN message is sent to open the device, then a MCI_SET, with a MCI_SET_DOOR_OPEN parameter.  Then the device is closed with MCI_CLOSE.  Again, this code doesn't check to see the current status of the cdrom drive (opened or not), but i didn't think you needed that.  I'm not sure if this code will work for you, since I only learned it today (researched it for about an hour till i got my cdrom drive door to open).  On a related note, if you are a PC Magizine subscriber, you can obtain a Delphi source of how to open a cd-rom drive door (this is the source i converted to C, this code did not use the element parameter, so i was unsure of how to tell the mci command which drive) from www.pcmag.com. I think it was in the 1997 march issue, not sure the title.  It was about cdrom drives in an "ask our experts" section i believe.  I hope this all explains it better, and further helps your code.  Regards,
                       PHUENE
0
 

Author Comment

by:zitt
ID: 1334532
I'm not a PCMag subscriber, so I can't get the source. Do you still have it?

I was able to implement part of your code. Now I've hit a bottleneck with Delphi's built-in media player. I'll need the source of TMediaPlayer componet before I can access the CDROM like I want to. My problem now is that I don't  currently use mciSendCommand() to access the CDROM, so I don't have the luxury of opening the drive with the Open_Elememt parameter.

John
0
 

Expert Comment

by:phuene
ID: 1334533
This is the code you requested (I understand most of it, but haven't used pascal in years).  Its from the Feb. 1997 issue of pcmag:

program cdinout;
uses mmSystem;
VAR
MCIO : TMCI_Open_Parms;
MCIS : TMCI_Status_Parms;
begin
MCIO.lpstrDeviceType := PChar(MCI_DEVTYPE_CD_AUDIO);
IF mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE OR MCI_OPEN_TYPE_ID OR MCI_OPEN_SHAREABLE, LongInt(@MCIO)) = 0 THEN
BEGIN
MCIS.dwItem := MCI_STATUS_READY;
mciSendCommand(MCIO.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM
OR MCI_WAIT, LongInt(@MCIS));
IF MCIS.dwReturn <&gt; 0 THEN
mciSendCommand(MCIO.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0)
ELSE
mciSendCommand(MCIO.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
mciSendCommand(MCIO.wDeviceID , MCI_CLOSE, MCI_WAIT, 0);
END;
end.

Hope this helps, sorry for the formatting. Regards,
       PHUENE
0
 

Author Comment

by:zitt
ID: 1334534
The code phuene gave us will work, except my data shows we should have used MCI_OPEN_ELEMENT_ID instead of MCI_OPEN_ELEMENT in the first MCISendCommand(). Without MCI_OPEN_ELEMENT_ID my program spits out error messages like:

MMSYSTEM011 An invalid parameter was passed to a system function.

Further tinkering gave the error:

MMSYSTEM296 The file cannot be played on the specified MCI device. The file may be corrupt, or not in the correct format.

Additionally, it should be noted that the code appears to work even under 16bit apps complied for Win3.x running on Win95. My hope is that it can be used under Windows 3.x too.

Thanks a bunch!
John
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now