c/c++ program for ejecting cd/dvd drive in computer

Programming, for all ages and all languages.
Post Reply
sanyam0108
Posts: 2
Joined: Sun Jan 12, 2014 9:50 pm

c/c++ program for ejecting cd/dvd drive in computer

Post by sanyam0108 »

I want to write a program for ejecting cd/dvd drive by c/c++ programming language. And I have the basic knowledge of c/c++ programming language.
Please help me with it and also suggest some notes or links associated with the question.
Please explain the logic also. :)
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by Love4Boobies »

First of all, there is no such thing as the C/C++ programming language. There exist, however, two incompatible languages called C and C++. Secondly, C and C++ are both abstract machines which know nothing about optical drives, just as they know nothing about mice, keyboard, displays, etc. In order to do what you want, you will need to use the services provided by your environment, which you have not mentioned.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
sanyam0108
Posts: 2
Joined: Sun Jan 12, 2014 9:50 pm

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by sanyam0108 »

Oh ! Got your point . If I have to talk about IDE , I can use any compiler like netbeans ,etc.
Suggest me one on which you worked on . I 'll work with that from now.! :)
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by Thomas »

Check out fasm examples , there is one file named beer.asm . It is trivial to convert it to C/C++ . Learn the win32 api , google on forgers win32 api tutorial

https://github.com/mcandre/fasm-win/blo ... R/BEER.ASM , api function : mciSendString

--Thomas

EDIT: invoke is macro in fasm . and other assemblers than expand to a CALL . Basically , you would have to convert the asm call into -> mciSendString("open cdaudio",NULL,NULL,NULL);
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by Love4Boobies »

I meant your target environment. For example, Thomas assumed Windows.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by sortie »

This is not the programming project you are looking for.

There is no reason to write such a program: It already exists on your favourite operating system and can probably easily be scripted. If you are willing to dig, you can probably find the system API.

For instance, my Linux system comes with an 'eject' command line utility that does exactly what you need. Assuming the drive is /dev/sr0, you just execute:

Code: Select all

eject /dev/sr0
I can see using strace that eject simply does some ioctl calls like CDROMEJECT, SG_GET_VERSION_NUM, SG_IO, and BLKRRPART on /dev/sr0.

Of course, if you are using Windows or anything silly, there's probably also a command to do that in the shell and there definitely is if you use some Windows scripting language. There surely is a function in the Windows API.

But really, with a bit of googling it's fairly trivial to find the system API for this or, better yet, existing programs in the system that does so that you can invoke from a script. This all depends on what you are really trying to accomplish. Ejecting the drive is pointless on its own unless you want a cup holder. What is the goal of your program?
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by Thomas »

Love4Boobies wrote:I meant your target environment. For example, Thomas assumed Windows.
yep, it is os specific . But from the way the question was phrased my brain heuristic returned windows :mrgreen:


--Thomas

PS : in *nix environments, you probabliy can eject with an icotl call ( basically search the web for the parameters . too lazy to do the searching for the poster ) .
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: c/c++ program for ejecting cd/dvd drive in computer

Post by sortie »

Thomas wrote:PS : in *nix environments, you probabliy can eject with an icotl call ( basically search the web for the parameters . too lazy to do the searching for the poster ) .
And too lazy to read my post just prior to yours that tell which ioctl calls. ;-)
Post Reply