Hello to all.
I'm writing a CD Player program under Windows 3.1x, wich uses MCI. I need
to obtain how many CD-ROM drives are installed on a computer (I'm going to
support up to 10 drives). The MCI command MCI_SysInfo should make the job,
shouldn't it? This is my procedure, written in Turbo Pascal for Windows 1.5
(but very easy to understand to C++ programmers, too):
procedure CDROM_Drives_Count;
var Info : TMCI_SysInfo_Parms; Options, Result : Longint;
Names : array [0..9] of PChar; NrDrives : Longint;
i, Stop : Byte;
begin
{I want to query about CD Audio device}
Info.wDeviceType := MCI_DevType_CD_Audio;
{I want to know how many drives are installed}
Options := MCI_SysInfo_Quantity;
{send the command: by now I don't care about Result; but I have a
doubt: SysInfo is sent directly rather than to a specified device, so I
think I can leave 0 the wDeviceID parameter of mciSendCommand, but I'm not
sure}
Result := mciSendCommand (0, MCI_SysInfo, Options, Longint (@Info));
{with the MCI_SysInfo_Quantity, lpstrReturn is also used to return a
DWORD, so a Longint}
NrDrives := Longint (Info.lpstrReturn);
{now I'm going to get the name of each CD Audio device and put them in
the Names array}
Options := MCI_SysInfo_Name;
{I'm going to support up to 10 drives, from 0 to 9, no more}
if NrDrives > 10 then Stop := 9 else Stop := NrDrives - 1;
{now repeat this operation Stop + 1 times}
for i := 0 to Stop do
begin
{get the name of device i}
Info.dwNumber := i;
{send the command}
Result := mciSendCommand (0, MCI_SysInfo, Options, Longint
(@Info));
{put the returned name into the Names array; dwRetSize specifies
the size of the returned string}
StrLCopy (Names[i], Info.lpstrReturn, Info.dwRetSize - 1)
end
end;
Now I should have the name of each drive in Names[DriveNumber]. I should be
able to get their wDeviceID with the mciGetDeviceID function.
First of all, is this procedure right? Am I mistaking something?
Well, this procedure hangs at two points:
1) Info.wDeviceType := MCI_DevType_CD_Audio;
[...]
Result := mciSendCommand (0, MCI_SysInfo, Options, Longint (@Info));
I tested it a lot of times and I found that the value of Info.wDeviceType
is not the value I want it to assume. It should assume the constant ID of
the "cdaudio" device type, but the program hangs (general protection
fault)! Why?
2) StrLCopy (Names[i], Info.lpstrReturn, Info.dwRetSize - 1)
Why doesn't this statement work? The procedure hangs (general protection
fault)! I really don't know why!
If you can help me, please please please put my e-mail address
(mauro...@tin.it) in the Cc: field of the reply. Moreover, if anyone can
suggest any GOOD documentation about MCI devices (with some examples), I'll
be grateful if he could contact me.
Thank you in advance.
--
Mauro Molinari
Internet e-mail: mauro...@mbox.vol.it / mauro...@tin.it