Solved

Control of CD Rom

Posted on 2004-09-14
13
292 Views
Last Modified: 2008-01-09
From console...  how would I open / close the CD tray?  I've looked up previous posts, which didn't help much :(  Thanks!

Regards,
Tony
0
Comment
Question by:fattumsdad
  • 7
  • 6
13 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12056847
Youc could just use

#include <windows.h>
#include <mmsystem.h>
#pragma comment ( lib, "winmm.lib")

void OpenCD ()
{

    MCIDEVICEID mciID;
    mciID = mciGetDeviceID ("CDAudio");

    // open drive
    mciSendCommand(mciID,MCI_SET,MCI_SET_DOOR_OPEN,0);

    mciSendString("Set CDAudio Door Open Wait", 0, 0, 0);

    return 0;
}
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12056963
Compiling source file(s)...
main.cpp
main.cpp:3: warning: ignoring #pragma comment
main.cpp: In function `void OpenCD()':
main.cpp:16: error: return-statement with a value, in function declared with a
void return type

Test.exe - 1 error(s), 1 warning(s)

What is a #pragma comment?
0
 
LVL 86

Expert Comment

by:jkr
ID: 12057007
Oh, this #pragma just pulls in 'winmm.lib' when using VC++ - just remove that one and the 'return' statement (again, a copy&paste accident :o)
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 86

Expert Comment

by:jkr
ID: 12057060
Oh, and to close the tray, use MCI_SET_DOOR_CLOSED instead
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12057172
main.cpp
Linking...
I:\Projects\Test\Debug\main.o(.text+0x32): In function `Z6OpenCDv':
I:\Projects\Test\main.cpp:9: undefined reference to `mciGetDeviceIDA@4'
I:\Projects\Test\Debug\main.o(.text+0x5b):I:\Projects\Test\main.cpp:12: undefined reference to `mciSendCommandA@16'
I:\Projects\Test\Debug\main.o(.text+0x82):I:\Projects\Test\main.cpp:14: undefined reference to `mciSendStringA@16'
C:\MinGWStudio\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.1\..\..\..\libmingw32.a(main.o)(.text+0x97):main.c: undefined reference to `WinMain@16

I'm thinking I'm missing a library somewhere...  is it the same one we used for the IP address program, libws2_32.a?
0
 
LVL 86

Expert Comment

by:jkr
ID: 12057336
No, this is a different one, it should be called libwinmm.a
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12057353
I was just about to post LOL.  I added libwinmm.a and I'm down to one error:

Linking...
C:\MinGWStudio\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.1\..\..\..\libmingw32.a(main.o)(.text+0x97):main.c: undefined reference to `WinMain@16'

Test.exe - 1 error(s), 0 warning(s)

Any idea what it's complaining about?
0
 
LVL 86

Expert Comment

by:jkr
ID: 12057401
That's strange - are you setting it up to link a console app? It definitely works when doing so:

#include <windows.h>
#include <mmsystem.h>
#pragma comment ( lib, "winmm.lib")

int main ()
{

    MCIDEVICEID mciID;
    mciID = mciGetDeviceID ("CDAudio");

    // open drive
    mciSendCommand(mciID,MCI_SET,MCI_SET_DOOR_OPEN,0);

    mciSendString("Set CDAudio Door Open Wait", 0, 0, 0);

    return 0;
}
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12057491
Oh!  I got it now...  I kept it as void main() vice int.  Made the changes, and it works great.  One last question...  to close, I put the MCI_SET_DOOR_CLOSED like this:

mciSendCommand(mciID, MCI_SET,MCI_SET_DOOR_OPEN,0);
mciSendString("Set CDAudio Door Close Wait", 0, 0 , 0);

Wild guess there.....
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12057513
Typeo...  I meant CLOSED vice OPENED in the above statement...
0
 
LVL 86

Expert Comment

by:jkr
ID: 12057549
Yes, that should work - cannot test it though, since I only have a laptop here at the moment.
0
 
LVL 86

Expert Comment

by:jkr
ID: 12057571
Correction - that should be

mciSendCommand(mciID, MCI_SET,MCI_SET_DOOR_CLOSED,0);
mciSendString("Set CDAudio Door Closed Wait", 0, 0 , 0); // <-- 'Closed' instead of 'Close'
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12057595
Woohoo, works great!  Again, thank you!!!!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question