Thread: Using exit codes ? (errorlevel 's) and Playing a wav file

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    4

    Using exit codes ? (errorlevel 's) and Playing a wav file

    Hey, i'm kinda new to C programming, i've search the net through yahoo/google and searched this site and board and still haven't been able to answer the two below problems.

    I'm compiling a pre-written C program, a very small DOS command line tool, and was wonder if there was a quick and easy way for me to incorporate errorlevel's.

    What i'm really wanting to do is launch the program from a bat file, and if the program exits with an error, the bat file skips to the end and finishes.

    The bat file part I can do, bat programming isn't a problem.
    Code:
    if errorlevel 1 goto end
    The problem is incorporating the errorlevels / exit codes into the C program.

    Any idea's ?

    The other problem i'm having is i'd like the DOS command line program to play a wav file when it finishes, so I know that its finished.

    I'm really not good with C yet so any pointers would be very appreciated
    Thank you in advance

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include <stdlib.h>
    
    int error = EXIT_SUCCESS;
    
    int main( void )
    {
        ...do stuff...
    
        return error;
    }
    Hope is the first step on the road to disappointment.

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Code:
    enum
    {
    SUCCESS=0x0,FAILURE,MEM,ETC
    };
    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  4. #4
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    like windows
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Note: this is for C++

    http://www.world-voices.com/resources/cpp.html
    an example:
    Code:
    #include <iostream.h>
    #include <CString.h>
    #include <windows.h>
    #include <conio.h>
    #pragma comment( lib, "winmm.lib" )								// Search For WinMM Library While Linking
    bool opened=false;
    void playM(CString);
    void closeM();
    int main()
    {
    	CString buf;
    	CString buf2;
    	int init;
    	cout<<"Enter path of midi file: ";
    	getline(cin,buf);
    	buf2 = "Do you want to play: "+buf;
    	init=MessageBox(NULL,buf2.std_str(),"PlayMusic",MB_YESNO|MB_ICONQUESTION);
    	if(init==IDYES)
    	{
    		playM(buf);
    		MessageBox(NULL,"Press OK to stop Playing Music","Title goes here dork!",MB_OK);
    		buf2="play "+buf;
    
    		mciSendString(buf2.std_str(),NULL,0,NULL);
    		MessageBox(NULL,"Press OK to stop Playing Music","Title goes here dork!",MB_OK);
    		closeM();
    	}
    	
    
    	return 0;
    }
    void playM(CString buf)
    {
    	CString buf2;
    	buf.makeDirectoryPath();
    	buf2= "play "+buf;
    	buf = "open "+buf+" type sequencer";
    	mciSendString(buf.std_str(),NULL,0,NULL);
    	mciSendString(buf2.std_str(),NULL,0,NULL);
    }
    void closeM()
    {
    	mciSendString("close all",NULL,0,NULL);
    }
    a program I wrote a while ago...
    if u want CString....
    CString.zip

    -LC
    Last edited by Lynux-Penguin; 07-30-2003 at 01:59 PM.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    4
    Well that all looks extremely helpful, thanks for the input guys.
    I'll take a look, wamp it in my code and see what happens.

    This always seems like a good idea to newbies - until you've run your program several times. Then you will grow to loath and detest your program and take it out again.
    Yes I know it sounds like a bad idea but for the program i'm doing it would be extremely useful.

    So thanks to Lynux-Penguin for his input on that one.

    Appreciate the help, Thanks all.

Popular pages Recent additions subscribe to a feed