Code:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#if defined(_MSC_VER)
# pragma comment(lib, "winmm.lib")
#endif
void EjectAll(void)
{
TCHAR command[1000];
TCHAR result[1000];
UINT count;
UINT i;
/* Get the number of cdaudio devices available. */
mciSendString(TEXT("sysinfo cdaudio quantity"), result, 1000, NULL);
count = _tcstoul(result, NULL, 10);
for (i = 1; i <= count; i++)
{
/* Get the name of this device. */
wsprintf(command, TEXT("sysinfo cdaudio name %u"), i);
mciSendString(command, result, 1000, NULL);
/* Open this device. */
wsprintf(command, TEXT("open %.500s alias cd1"), result);
mciSendString(command, NULL, 0, NULL);
/* Eject this device. */
mciSendString(TEXT("set cd1 door open wait"), NULL, 0, NULL);
/* Close this device. */
mciSendString(TEXT("close cd1"), NULL, 0, NULL);
}
}
int main(void)
{
EjectAll();
getchar();
return 0;
}