Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

CD routines

Posted on 2001-06-27
7
230 Views
Last Modified: 2010-04-06
I need 3 routines: Eject, Retract and Count tracks(without using MediaPlayer).

I know there is an mcisendstring or something like that but it does not handle the situation of having more than one CD drive(for example if someone has CD and CDR)
0
Comment
Question by:duke_n
  • 5
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6231516
uses MMSystem;


// to open
mciSendString('Set cdaudio door open wait', nil, 0, handle);

// yo close
mciSendString('Set cdaudio door closed wait', nil, 0, handle);


I have no idea how to count the tracks...
0
 
LVL 1

Author Comment

by:duke_n
ID: 6231595
And what If I wanna do that(eject/retract) to the second/third/../twentieth CD?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6231805
Here's roughly how to get the number of tracks:

var mciOpenParms: TMCI_Open_Parms;
    mciStatusParms: TMCI_Status_Parms;
    mciSetParms: TMCI_Set_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, Cardinal(@mciOpenParms));
  mciStatusParms.dwItem := MCI_STATUS_NUMBER_OF_TRACKS;
  if mciSendCommand(mciOpenParms.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@mciStatusParms)) = 0 then
    ShowMessage(IntToStr(mciStatusParms.dwReturn));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 6232115
Ok here is is:

uses MMSystem;

const
  DRIVE = 'G:';

procedure TForm1.GetNumberOfTracksClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
    mciStatusParms: TMCI_Status_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciStatusParms.dwItem := MCI_STATUS_NUMBER_OF_TRACKS;
  if mciSendCommand(mciOpenParms.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@mciStatusParms)) = 0 then
    ShowMessage(IntToStr(mciStatusParms.dwReturn));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;

procedure TForm1.OpenCDClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;

procedure TForm1.CloseCDClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;
0
 
LVL 1

Author Comment

by:duke_n
ID: 6232207
exceptional.
thank you very much.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6232217
Here is how to find CDROM drives:

procedure ListDrives(Strings: TStrings);
const BufSize = 256;
var
  Buffer: PChar;
  P: PChar;
begin
  GetMem(Buffer, BufSize);
  try
    Strings.BeginUpdate;
    try
      Strings.Clear;
      if GetLogicalDriveStrings(BufSize, Buffer) <> 0 then
      begin
        P := Buffer;
        while P^ <> #0 do
        begin
          if GetDriveType(PChar(P)) = DRIVE_CDROM then
            Strings.Add(P);
          Inc(P, StrLen(P) + 1);
        end;
      end;
    finally
      Strings.EndUpdate;
    end;
  finally
    FreeMem(Buffer, BufSize);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListDrives(ListBox1.Items);
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6232221
Thanks  :o)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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