Thread: ejecting multiple cd-rom drives

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    ejecting multiple cd-rom drives

    hi!

    i know that this code ejects a 1st cd-rom drive :

    mciSendString("open cdaudio alias cd1", 0, 0, 0);
    mciSendString("set cd1 door open wait", 0, 0, 0);

    but how can i eject a 2nd and a 3rd cd-rom drive?
    i tried this code and failed:

    mciSendString("open cdaudio1 alias cd2", 0, 0, 0);
    mciSendString("set cd2 door open wait", 0, 0, 0);
    mciSendString("open cdaudio2 alias cd3", 0, 0, 0);
    mciSendString("set cd3 door open wait", 0, 0, 0);

    please help.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    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;
    }

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    i'll try that. Thanx a bunch.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 01:34 PM
  2. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  3. CD rom troubles...
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2003, 10:56 PM
  4. SCSI drivers... device conflict... no CD drives
    By CodeMonkey in forum Tech Board
    Replies: 2
    Last Post: 09-10-2003, 06:48 AM
  5. Probs with CD drives
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-11-2002, 11:09 AM