Solved

Control of CD Rom

Posted on 2004-09-14
13
290 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now