Solved

CD routines

Posted on 2001-06-27
7
224 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
Comment Utility
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
Comment Utility
And what If I wanna do that(eject/retract) to the second/third/../twentieth CD?
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
Comment Utility
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
Comment Utility
exceptional.
thank you very much.
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
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
Comment Utility
Thanks  :o)
0

Featured Post

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.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

6 Experts available now in Live!

Get 1:1 Help Now