Thread: CD Drive eject

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    52
    Rep Power
    12

    CD Drive eject


    How do you make the CD Drive open?
    Roar!!!
  2. #2
  3. No Profile Picture
    "Null, The Terminator"
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    11
    Rep Power
    0
    This is a code example demonstrating how to open the CD hatch in C.

    You have to use the Microsoft Media Control Interface (MCI).

    Maybe you should consider using VB instead of WIN32 API.

    There are a lot of source codes examples in VB that show you how to use the MCI devices.

    Many samples use OCX, which makes it quite simple to work with.


    void CDEject(WORD wGlobalDeviceID)

    {


    MCI_SET_PARMS mciset;


    DWORD dwFlags;


    DWORD dwRes;


    dwFlags=MCI_SET_DOOR_OPEN;


    dwRes=mciSendCommand(wGlobalDeviceID,MCI_SET,dwFlags,(DWORD)(LPSTR)&mciset);


    if (dwRes)


    {


    ErrorProc(dwRes);


    return;


    }


    return;


    }

    source : http://www.ddj.com/forums/thread.htm...&threadid=1982
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    55
    Rep Power
    12
    Here is the code for linux:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <linux/cdrom.h>
    
    #define DEVICE "/dev/cdrom"
    
    int main(int argc, char **argv)
    {
    	int fd, ret;
    
    	fd = open(DEVICE, O_RDONLY);
    	if(fd == -1)
    	{
    		fprintf(stderr, "  Error: Unable to open %s.\n", DEVICE);
    		return -1;
    	}
    
    	ret = ioctl(fd, CDROMEJECT, 0);
    	if(ret == -1)
    	{
    		fputs("  Error: Unable to set device perametres.\n", stderr);
    		close(fd);
    		return -2;
    	}
    
    	close(fd);
    	return 0;
    }
  6. #4
  7. No Profile Picture
    "Null, The Terminator"
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    11
    Rep Power
    0
    doesnt worx man.....
    Error: Unable to open /dev/cdrom

    i tried it changing to /dev/cdrom0...
    even then same state
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    55
    Rep Power
    12
    It's not the code that's wrong, it's the path you are passing or your box.

IMN logo majestic logo threadwatch logo seochat tools logo