Solved

Control of CD Rom

Posted on 2004-09-14
13
296 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
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!

 
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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 124
Excel/Word Add-in in what language? 5 144
Compile GLUT with Visual Studio 2015 1 207
How to convert MFC::CString to UTF8 wchar_t* 10 387
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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