×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

MCI command strings

MCI command strings

MCI command strings

(OP)
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.
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:

status = mciSendString("status cdaudio mode", Buffer, 255, NULL);

It always says the tray is open if it is empty (No CD).
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?
Full code follows:

#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include <string.h>

void main()
{
DWORD status;
char Buffer[256] = "not ready";

_InitEasyWin();
status = mciSendString("open cdaudio", NULL, 0, NULL);
if (status != 0)
{
printf( "error!" );
}


status = mciSendString("status cdaudio mode", Buffer, 255, NULL);
if (status != 0)
{
printf( "error! 1" );
}
printf("-->%s<--", Buffer);

if ( strcmp( "open", Buffer ) == 0)
{
status = mciSendString("set cdaudio door closed", NULL, 0, NULL);
if (status != 0)
{
printf( "error!" );
}
}
else
{
status = mciSendString("set cdaudio door open", NULL, 0, NULL);
if (status != 0)
{
printf( "error!" );
}
}


mciSendString("close cdaudio", NULL, 0, NULL);
}


Kim_Christensen@telus.net
Home Page

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close