Below is some experimental code I wrote while trying to figure out how to control the CD-ROM drive via MCI command strings. Excuse the _InitEasyWin() I just use it as a quick and dirty way to try out ideas in Borland C++ 3.1 without writing a whole swag of code.<br>
Basically, the code is supposed to check to see if the CD door is open and if it is, close it. If the door is closed it should open when the program is run. The problem is with the line:<br>
<br>
status = mciSendString("status cdaudio mode", Buffer, 255, NULL);<br>
<br>
It always says the tray is open if it is empty (No CD).<br>
If there is a CD in the tray, then the program acts as intended. Is there a way around this? ie: tell if the tray is opened/closed with no CD in the tray?<br>
Full code follows:<br>
<br>
#include <windows.h><br>
#include <mmsystem.h><br>
#include <stdio.h><br>
#include <string.h><br>
<br>
void main()<br>
{<br>
DWORD status;<br>
char Buffer[256] = "not ready";<br>
<br>
_InitEasyWin();<br>
status = mciSendString("open cdaudio", NULL, 0, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error!" );<br>
}<br>
<br>
<br>
status = mciSendString("status cdaudio mode", Buffer, 255, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error! 1" );<br>
}<br>
printf("-->%s<--", Buffer);<br>
<br>
if ( strcmp( "open", Buffer ) == 0)<br>
{<br>
status = mciSendString("set cdaudio door closed", NULL, 0, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error!" );<br>
}<br>
}<br>
else<br>
{<br>
status = mciSendString("set cdaudio door open", NULL, 0, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error!" );<br>
}<br>
}<br>
<br>
<br>
mciSendString("close cdaudio", NULL, 0, NULL);<br>
}<br>
<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
Basically, the code is supposed to check to see if the CD door is open and if it is, close it. If the door is closed it should open when the program is run. The problem is with the line:<br>
<br>
status = mciSendString("status cdaudio mode", Buffer, 255, NULL);<br>
<br>
It always says the tray is open if it is empty (No CD).<br>
If there is a CD in the tray, then the program acts as intended. Is there a way around this? ie: tell if the tray is opened/closed with no CD in the tray?<br>
Full code follows:<br>
<br>
#include <windows.h><br>
#include <mmsystem.h><br>
#include <stdio.h><br>
#include <string.h><br>
<br>
void main()<br>
{<br>
DWORD status;<br>
char Buffer[256] = "not ready";<br>
<br>
_InitEasyWin();<br>
status = mciSendString("open cdaudio", NULL, 0, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error!" );<br>
}<br>
<br>
<br>
status = mciSendString("status cdaudio mode", Buffer, 255, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error! 1" );<br>
}<br>
printf("-->%s<--", Buffer);<br>
<br>
if ( strcmp( "open", Buffer ) == 0)<br>
{<br>
status = mciSendString("set cdaudio door closed", NULL, 0, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error!" );<br>
}<br>
}<br>
else<br>
{<br>
status = mciSendString("set cdaudio door open", NULL, 0, NULL);<br>
if (status != 0)<br>
{<br>
printf( "error!" );<br>
}<br>
}<br>
<br>
<br>
mciSendString("close cdaudio", NULL, 0, NULL);<br>
}<br>
<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>