Solved

Control of CD Rom

Posted on 2004-09-14
13
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

729 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