[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Control of CD Rom

Posted on 2004-09-14
13
Medium Priority
?
304 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

649 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