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.
c/c++ program for ejecting cd/dvd drive in computer
-
- Posts: 2
- Joined: Sun Jan 12, 2014 9:50 pm
- Love4Boobies
- 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
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 ]
[ Project UDI ]
-
- Posts: 2
- Joined: Sun Jan 12, 2014 9:50 pm
Re: c/c++ program for ejecting cd/dvd drive in computer
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.!
Suggest me one on which you worked on . I 'll work with that from now.!
Re: c/c++ program for ejecting cd/dvd drive in computer
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);
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);
- Love4Boobies
- 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
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 ]
[ Project UDI ]
Re: c/c++ program for ejecting cd/dvd drive in computer
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:
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?
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
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?
Re: c/c++ program for ejecting cd/dvd drive in computer
yep, it is os specific . But from the way the question was phrased my brain heuristic returned windowsLove4Boobies wrote:I meant your target environment. For example, Thomas assumed Windows.
--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 ) .
Re: c/c++ program for ejecting cd/dvd drive in computer
And too lazy to read my post just prior to yours that tell which ioctl calls.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 ) .