Hi,

I was wondering if there is a way to control hardware in C++, such as opening and closing a CD drive.

Thanks in advanced,
C++

Yes, but not with straight C++. You're looking at operating specific API calls.

ok, lets say im running Win XP Home, SP2

Can you tell me how to do it now?


Thank you,
C++

To me you have not even shown an effort. If you notice this board helps other coders to become better codes - this is only going to take place when one posts up his / her code and let us see what they understand. Such demands like these won't help anyone nor yourself to become a better coder! I'm not sure that you even know the basics never mind playing around with the API interface!

>Can you tell me how to do it now?
Sure, go to msdn.microsoft.com and read. Normally I would give you some code, but I find your "gimme gimme" tone annoying.

Hi AcidBurn and Narue,

Sorry for my bad attidute. Just so you know, this wasn't a class assignment(I'm not even in a programming class). I was actually trying to make a CD player.
Thanks for telling me to look at msdn.microsoft.com.

AcidBurn, I actually have absolutely no idea how to do this. I just started learning C++ and I'm still a beginner.

--
C++

Then I strongly suggest you start from the beginning, either by taking a programming course, or attempt to get a book and work through! Don't expect to find yourself playing with that sort of stuff soon! I've had almost 1 yer doing C and C++...and we havent even started that yet! (Next year) ..........

i already know Java, so i thought that might have helped. I gues not though...

Here what I like to call the lazy man's method!

Interprocess communication can help improve the functionality of your program.

// Command line approach
#include <stdlib.h>
...
// To open
system("wineject -open d:"); // Note: d: can be any letter you pick.
// To close
system("wineject -close d:"); // Note: d: can be any letter you pick.
-----------------------------------------------------------
// Windows Approach
#include <windows.h>
...
//To Open
WinExec("wineject -open d:", SW_HIDE);
//To close
WinExec("wineject -close d:", SW_HIDE);
------------------------------------------------------------
Hope this helps, you can get wineject from: http://www.bountyx.net/files/wineject.exe

The above assumes that wineject.exe is in the same location as your program's exe. If you wish to use configurable drive letters with the commands you must get rid of the "d:" part and concatenate your own drive letter to the string.

------------------------------------------------------------

That's the easy, interprocess communication approach. Now lets use something more direct. You expressed using Windows XP. Luckily, there is API support for this type of communication. This is what your looking for: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/imapi_interfaces.asp

The IMAPI interface through the windows api will make things a breeze =) . Documentation and examples available at MSDN.com .

Now lets take it a step further. How does communication with the CDROM work? Well it is true that the API may handle this a little differently as you go from platform to platform, but layers exist to compensate for procedures that are not explicitly available in the API.

Such layers are ASPI layers and IMAPI layers. In fact, Nero provides a free aspi layer. WinAspi.dll is also an option (but only for windows). For more information about a [almost] platform independent approach to communicating with the CDROM drives, see http://cdrecord.berlios.de/old/private/cdrecord.html

CDRECORD implements an ASPI layer to provide a common interface to interact with CDROM drives. Not only can you eject a cd, you can write data!

Good Luck!

thank you very much bountyX, that REALLY helped. on the program u made, wineject, how do you put the icon on the bottom of the screen and create the options when u right click?

Thanx,
C++

can someone please answer my question?

thanx

maybe we don't know?

i think bountyx knows, he made a program that does that. Read post #9.

C++

Check out: http://www.codeproject.com/shell/systemtray.asp

Although the explanation refers to an MFC based example, at the top of the page you can download a NON-MFC example.

You will need to know how the windows API works and how to code in windows API. If you don't check out: http://www.winprog.org/tutorial/

You can also do it without any new libraries by just using windows.h
This a bit more confusing but msdn.com outlines the functions very well. Search for:

NOTIFYICONDATA structure
Shell_NotifyIcon

thank you very much. that really helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.