Trying to eject D drive using code, but not working... :(

This is a discussion on Trying to eject D drive using code, but not working... :( within the C++ Programming forums, part of the General Programming Boards category; Alright, I'm really at the end of my rope here. I'm trying to devise a CD with an autorunning password ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    3

    Question Trying to eject D drive using code, but not working... :(

    Alright, I'm really at the end of my rope here. I'm trying to devise a CD with an autorunning password input program that ejects the disk if the correct password isn't put in. I've been able to create the password prompt and autorun components of this idea on my own, but ejecting the disk is something I've been having trouble with.

    I've been scouring the internet for a way to open the D drive indirectly via code. I finally came upon this programming forum, and I found some code for doing it, but it's not working.

    Alright, here was the original code I found by searching. The page can be found here

    Remember, the function of the code is to open the D drive...

    Code:
    //** mci files for access to cd drive
    //** insure to include the winmm.lib in the links tab of the project settings
    #include "mmsystem.h"
    #include "vfw.h"
    
    
    void CCupHolderDlg::OnButton1() 
    {
    
    	MCIERROR i = mciSendString("open cdaudio alias cd2", 0, 0, 0);
    	
    	if( i )
    		ShowError( (DWORD)i );
    
    
    	MCIERROR error = mciSendString("set cd2 door open wait", 0, 0, 0);
    
    	if( error )
    		ShowError( error );
    
    
    //	::Sleep( 3000 );
    //	error = mciSendString("set cd2 door closed wait", 0, 0, 0);
    
    	if( error )
    		ShowError( error );
    
    	error = mciSendString("close cd2", 0, 0, 0);
    	if( error )
    		ShowError( error );
    
    	Invalidate( FALSE );
    
    }
    I changed
    Code:
    void CCupHolderDlg::OnButton1()
    to plain old "main ()", because from what I know about C and C++ (which is very little, I work with FORTRAN and PYTHON mainly), that will probably make the script run independently, instead of conditionally, so I'll be able to simply run the program if the password is wrong, instead of having to embed the password thing into C++, which I'd have even less of an idea how to do. So I just switched the void line to main ()

    I tried compiling it using Borland command prompt compiler (not the IDE, I'm not about to spend two hours downloading and installing that), and I got 26 errors, and the errors weren't in this code, they were in "mmsystem.h" I tried using a different compiler, but I got the same problem.

    EDIT: See the below two posts


    Does anyone know why this isn't working? please?

    I did not, do as the code stated, and include winmm.lib in the links tab of the project settings, because I'm not running any IDE, I'm running only a compiler with no GUI, and if there's an equivalent way to do whatever "including the winmm.lib in the links tab of the project settings" is on a compiler, I have no idea what it is. Is my problem a result of me not linking to this? And if yes, please tell me how I'm to do this confusing task.

    Thank you to anyone who replies.
    Last edited by snowfrog; 05-07-2005 at 04:33 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    I'm fairly sure you need to include windows.h before any other windows specific header file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    3
    Alright, now I have, and that's fixed a lot of the errors, but now I'm getting two errors.

    Line 14: Call to undefined function 'ShowError' in function main()
    Line 33: Call to undefined function 'invalidate' in function main()

    huh...

    so anyone know what to do now? Lemme see if I can find a header file which includes those, but in the meantime, if you know the answer to this new problem, please do tell.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    3

    Thumbs up

    Nevermind, I figured it out.

    Code:
    #include "windows.h"
    #include "mmsystem.h"
    #include "vfw.h"
    
    main () 
    {
            mciSendString("open cdaudio alias cd2", 0, 0, 0);
    	
            mciSendString("set cd2 door open wait", 0, 0, 0);
    
    
    }
    This code opens the CD tray on running. No errors, no warnings, fast enough, problem solved. Thank zod.
    Last edited by snowfrog; 05-07-2005 at 07:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with previously working internet code
    By abachler in forum Windows Programming
    Replies: 11
    Last Post: 04-10-2009, 04:11 AM
  2. Code not working?
    By Elysia in forum C++ Programming
    Replies: 12
    Last Post: 04-06-2009, 01:57 AM
  3. Replies: 3
    Last Post: 02-24-2009, 07:49 PM
  4. C code not working
    By D3ciph3r in forum C Programming
    Replies: 2
    Last Post: 05-27-2005, 04:13 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21