944,149 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4510
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 17th, 2005
0

Controlling Hardware

Expand Post »
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++
Similar Threads
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Apr 17th, 2005
0

Re: Controlling Hardware

Yes, but not with straight C++. You're looking at operating specific API calls.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 17th, 2005
0

Re: Controlling Hardware

ok, lets say im running Win XP Home, SP2

Can you tell me how to do it now?


Thank you,
C++
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Apr 17th, 2005
0

Re: Controlling Hardware

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!
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Apr 17th, 2005
0

Re: Controlling Hardware

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 17th, 2005
0

Re: Controlling Hardware

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++
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Apr 18th, 2005
0

Re: Controlling Hardware

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) ..........
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Apr 19th, 2005
0

Re: Controlling Hardware

i already know Java, so i thought that might have helped. I gues not though...
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Apr 19th, 2005
0

Re: Controlling Hardware

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!
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004
Apr 21st, 2005
0

Re: Controlling Hardware

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++
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: linking open gl
Next Thread in C++ Forum Timeline: parking fee





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC