Opening CD tray

What functions would I use to open the CD tray?

I've received mixed research results on this, some long and some simple. I've found a few snippets (that I try to use an example) but they don't work :\
what os?
Windows XP SP2 But I'd like to know how to do it with all current OS's if possible, but the priority is XP
Last edited on
Have you tried this one? It uses mciSendString()....

http://www.daniweb.com/code/showthread.php?t=216376

Seems alright at first glance...
I haven't tried it yet but the comments below the article looked promising!
There is also the DeviceIOCTL routines.


Have you tried this one? It uses mciSendString()....

http://www.daniweb.com/code/showthread.php?t=216376

Seems alright at first glance...
I haven't tried it yet but the comments below the article looked promising!


I was thinking of mciSendString() as well, I found a similiar snippet to that one and it didnt work, I'll try this one and we'll see. As long as it is a working snippet I can learn from it.

I will also look into the DeviceIOCTL routines.
Last edited on
BTW, doing this will be different for every OS...
Okay well mciSendString() worked. This is what I have. I had to include libwinmm.a with Dev-C++ in order for it to work (As the snippet posted by Dr3DsY directed) This what I've got:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
 
using namespace std;
 
int main()
{

    mciSendString("open CDAudio", NULL, 0, NULL);
    cout << "CD Tray is opening please wait..." << endl;
    mciSendString("set CDAudio door open", NULL, 0, NULL);
    cout << "CD Tray is open please place in or remove CD and ";
    system("pause");
    mciSendString("set CDAudio door closed", NULL, 0, NULL);
    mciSendString("close CDAudio", NULL, 0, NULL);
    return 0;
}


:D
Last edited on
so this one I am guessing is compatible with windows XP, if anyone knows of newer OS commands for the CD tray please elaborate or a more "universal" way to do it.
Le bump! Nothing?

From all the people I've given the above snippet to it has worked fine. If no more suggestions I will mark this topic as solved.
Topic archived. No new replies allowed.