Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to eject and close the cdrom

Posted on 1998-12-10
11
Medium Priority
?
470 Views
Last Modified: 2011-09-20
I want to know without tmediaplayer how can i eject and close the cdrom? and if i have two cdrom driver how can i know what cdrom i will eject?
0
Comment
Question by:chengjian
[X]
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
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1350460
hi'
put mmsystem in your uses clause then to open do:
mcisendstring('set cdaudio door open wait',nil,0,handle);

and to close do:
mcisendstring('set cdaudio door closed wait',nil,0,handle);

see more info in mm.hlp under find open / opening simple devices

Regards barry


0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1350461
hi, inthe.

problem is still to determine which cd-rom to operate in a multiple-cd-rom machine...

Black Death.
0
 
LVL 1

Author Comment

by:chengjian
ID: 1350462
Thanks a lot.
But BlackDeath has told you what the problem is!
Thanks BlackDeath.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthe
ID: 1350463
sorry all i can only do this with tmedia player but i would just make it invisible anyway .
you will have to do something with winapi GETLOGICALDRIVES
it will return device types and the one your after is dtCDAudio
 
  (reject my answer next time i'll read ALL of the question:-)
Barry

0
 
LVL 44

Expert Comment

by:bruintje
ID: 1350464
Hi Chengjian,

Well combine this from the Borland TI with the answer from Inthe, when I saw this Q first didn't have the time to find out how to close the CDROM. So now you can specifically make a call to a CDROM in drive A to Z

 
 
 
 
Frequently Asked Questions

How can I eject a CD-ROM in code?


Question:


How can I eject a CD-ROM in code?

Answer:


You can use the Windows API function GetDriveType() to test

if the drive is a CD-ROM  drive then use the TMediaPlayer

(even if the CD is not an Audio CD) to eject the CD.



Example:



function IsDriveCD(Drive : char) : longbool;

var

  DrivePath : string;

begin

  DrivePath := Drive + ':\';

  result := LongBool(GetDriveType(PChar(DrivePath)) and DRIVE_CDROM);

end;



function EjectCD(Drive : char) : bool;

var

  mp : TMediaPlayer;

begin

  result := false;

  Application.ProcessMessages;

  if not IsDriveCD(Drive) then exit;

  mp := TMediaPlayer.Create(nil);

  mp.Visible := false;

  mp.Parent := Application.MainForm;

  mp.Shareable := true;

  mp.DeviceType := dtCDAudio;

  mp.FileName := Drive + ':';

  mp.Open;

  Application.ProcessMessages;

  mp.Eject;

  Application.ProcessMessages;

  mp.Close;

  Application.ProcessMessages;

  mp.free;

  result := true;

end;



procedure TForm1.Button1Click(Sender: TObject);

begin

  if not EjectCD('D') then

    ShowMessage('Not A CD Drive');

end;

Hope this helps
:O)
Bruintje.

0
 
LVL 1

Author Comment

by:chengjian
ID: 1350465
Your program works good but i do not want tmediaplayer
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1350466
Hmm got to the read question better next time.
0
 
LVL 1

Author Comment

by:chengjian
ID: 1350467
I can Barely accept the answer for the only points
How can i give both inthe and bruintje points?
0
 
LVL 17

Expert Comment

by:inthe
ID: 1350468
dont worry bout the points mate reject my answer and bruintje
can leave a message as an answer as his way is only way i know how to do what your after.
regards barry
0
 
LVL 1

Author Comment

by:chengjian
ID: 1350469
inthe: Thanks for your answer. i am sorry.
bruintje: Put it as answer

Thanks all

0
 
LVL 44

Accepted Solution

by:
bruintje earned 20 total points
ID: 1350470
Happy new year everyone.

And thanks Barry.

bruintje :O)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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