Thread: Eject a cd with C++ code

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    Eject a cd with C++ code

    Hi.
    I want to try to open my cd drive with a C++ code, I searched on this forum and found something but it isn't working (http://cboard.cprogramming.com/showt...ight=eject+cd). I got 3 questions; (please look at that thread) it sais: "insure to include the winmm.lib in the links tab of the project settings".
    1. What is "winmm.lib"?
    2. What does that bold line means, and what do you need to do?
    3. Do you also got to "include" it with "PlaySound()"?

    Now on the end of that thread you see a new code but it isn't working.
    I have a couple of questions on that to:
    1. Do I need to "include the winmm.lib in the links tab of the project settings"?
    2. How do I "include the winmm.lib in the links tab of the project settings"?
    3. Does that code opens a cd drive?
    4. How can I eject a cd with C++ code?
    Thanks for any help.
    Last edited by Yuri; 08-23-2005 at 09:17 AM.

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    You can use SDL library for work with CD-ROM and other multimedia stuff...

    http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API , section 7.
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  3. #3
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    That is in C and doesn't really seem to work. I need some sort of SDL.h.

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    Quote Originally Posted by Yuri
    That is in C and doesn't really seem to work. I need some sort of SDL.h.
    Here's C++ code, which works perfectly in DevC++ (you can found SDL on one of updates servers) - but you must copy $DEVCPP/bin/SDL.dll to directory where you have this code...:

    PHP Code:
    #include <SDL/SDL.h>
    #include <windows.h>
    #include <iostream>
    using namespace std
    int main(int argcchar *argv[])
    {
     
    SDL_Init(SDL_INIT_CDROM);
     
    atexit(SDL_Quit);
     
    SDL_CD *handle;
     
    handle SDL_CDOpen(0);
     
    SDL_CDEject(handle);
     
    SDL_CDClose(handle);
     
     return 
    0;

    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    #include <windows.h>
    
    int main(int argc, char *argv[])
    {
        mciSendString("set cdaudio door open wait", NULL, 0, 0);
        return 0;
    }
    That opens drive D: on my computer using the mciSendString function. Yes, you must link winmm.lib into your project to do this. On DevC++, to link a library into your project, you open Project => Project Options... => Parameters tab => In the linker options box add -lwinmm. In VC++ you go to Project => Settings... => Link tab => Objects/libraries box => winmm.lib. Other: look at the compiler doc's.

  7. #7
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    (To Tonto)Thanks, but I do need to create a Project of it.
    Now I have 2 questions:
    1. Is there a way to "include" winmm.lib without using a project file?
    2. This opens my D drive, can I also open my E drive?
    Last edited by Yuri; 08-23-2005 at 01:05 PM.

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    where can I find all the commands for mcisendstring?

  9. #9
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  2. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM