fattumsdad
asked on
Control of CD Rom
From console... how would I open / close the CD tray? I've looked up previous posts, which didn't help much :( Thanks!
Regards,
Tony
Regards,
Tony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
Oh, and to close the tray, use MCI_SET_DOOR_CLOSED instead
ASKER
main.cpp
Linking...
I:\Projects\Test\Debug\mai n.o(.text+ 0x32): In function `Z6OpenCDv':
I:\Projects\Test\main.cpp: 9: undefined reference to `mciGetDeviceIDA@4'
I:\Projects\Test\Debug\mai n.o(.text+ 0x5b):I:\P rojects\Te st\main.cp p:12: undefined reference to `mciSendCommandA@16'
I:\Projects\Test\Debug\mai n.o(.text+ 0x82):I:\P rojects\Te st\main.cp p:14: undefined reference to `mciSendStringA@16'
C:\MinGWStudio\MinGW\bin\. .\lib\gcc- lib\mingw3 2\3.3.1\.. \..\..\lib mingw32.a( main.o)(.t ext+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?
Linking...
I:\Projects\Test\Debug\mai
I:\Projects\Test\main.cpp:
I:\Projects\Test\Debug\mai
I:\Projects\Test\Debug\mai
C:\MinGWStudio\MinGW\bin\.
I'm thinking I'm missing a library somewhere... is it the same one we used for the IP address program, libws2_32.a?
No, this is a different one, it should be called libwinmm.a
ASKER
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\mingw3 2\3.3.1\.. \..\..\lib mingw32.a( main.o)(.t ext+0x97): main.c: undefined reference to `WinMain@16'
Test.exe - 1 error(s), 0 warning(s)
Any idea what it's complaining about?
Linking...
C:\MinGWStudio\MinGW\bin\.
Test.exe - 1 error(s), 0 warning(s)
Any idea what it's complaining about?
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_S ET,MCI_SET _DOOR_OPEN ,0);
mciSendString("Set CDAudio Door Open Wait", 0, 0, 0);
return 0;
}
#include <windows.h>
#include <mmsystem.h>
#pragma comment ( lib, "winmm.lib")
int main ()
{
MCIDEVICEID mciID;
mciID = mciGetDeviceID ("CDAudio");
// open drive
mciSendCommand(mciID,MCI_S
mciSendString("Set CDAudio Door Open Wait", 0, 0, 0);
return 0;
}
ASKER
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.....
mciSendCommand(mciID, MCI_SET,MCI_SET_DOOR_OPEN,
mciSendString("Set CDAudio Door Close Wait", 0, 0 , 0);
Wild guess there.....
ASKER
Typeo... I meant CLOSED vice OPENED in the above statement...
Yes, that should work - cannot test it though, since I only have a laptop here at the moment.
Correction - that should be
mciSendCommand(mciID, MCI_SET,MCI_SET_DOOR_CLOSE D,0);
mciSendString("Set CDAudio Door Closed Wait", 0, 0 , 0); // <-- 'Closed' instead of 'Close'
mciSendCommand(mciID, MCI_SET,MCI_SET_DOOR_CLOSE
mciSendString("Set CDAudio Door Closed Wait", 0, 0 , 0); // <-- 'Closed' instead of 'Close'
ASKER
Woohoo, works great! Again, thank you!!!!
ASKER
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?