Controlling Hardware

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Controlling Hardware

 
0
  #1
Apr 17th, 2005
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++
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Controlling Hardware

 
0
  #2
Apr 17th, 2005
Yes, but not with straight C++. You're looking at operating specific API calls.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: Controlling Hardware

 
0
  #3
Apr 17th, 2005
ok, lets say im running Win XP Home, SP2

Can you tell me how to do it now?


Thank you,
C++
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Controlling Hardware

 
0
  #4
Apr 17th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Controlling Hardware

 
0
  #5
Apr 17th, 2005
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: Controlling Hardware

 
0
  #6
Apr 17th, 2005
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++
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Controlling Hardware

 
0
  #7
Apr 18th, 2005
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) ..........
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: Controlling Hardware

 
0
  #8
Apr 19th, 2005
i already know Java, so i thought that might have helped. I gues not though...
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 8
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: Controlling Hardware

 
0
  #9
Apr 19th, 2005
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!
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: Controlling Hardware

 
0
  #10
Apr 21st, 2005
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++
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC