A program that plays a MIDI file and stops it, and than starts a different MIDI file. The same concept applies to .wav files mciSendString("play the_file",NULL,0,NULL); starts playing it, and as expected mciSendString("stop the_file",NULL,0,NULL); stops playing it.

// use mciSendString() to play and stop a midi music file
// you have to link with the winmm.lib file, or
// in the case of Dev-C++ link with libwinmm.a via
// Project>>Project Options>>Parameters>>Add Lib>>libwinmm.a
// a Dev-C++  console application

#include <iostream>
#include <windows.h>
#include <mmsystem.h>  // mciSendString()
#include <conio.h>
using namespace std;   // std::cout, std::cin

int main()
{
char wait;
        cout << "Looking for  onestop.mid  midi music file in" << endl;
        cout << "the windows media directory, wait just a second ...";

        // this midi file comes with Windows XP
        // you might have to change it to something you have
        mciSendString("play C:\\Windows\\Media\\onestop.mid",NULL,0,NULL);
        
        cout << endl << "Enter any letter to change to the next file.";
        getch(); // wait
        cout << endl << "Stopping onestop.mid" << endl;
        mciSendString("stop C:\\Windows\\Media\\onestop.mid",NULL,0,NULL);
                       // stops the file ^
        cout << "Looking for  flourish.mid  midi music file in" << endl;
        cout << "the windows media directory, wait just a second ...";
       // this midi file comes with Windows XP also
        mciSendString("play C:\\Windows\\Media\\flourish.mid",NULL,0,NULL);
        
        getch();  // wait
        return 0;
}

These looks very much like the code VegaSeat wrote earlier?

It essentailly is, but there were several people who couldn't quite figure out on how to stop the the midi file.

I have C++ 2005 Express Edition.
So when i use this code just to play a sound ".wav" file, the program doesn't work and it says " 'mmsystem': No such file or directory "

#include <iostream>
using namespace std;
#include <mmsystem> 
void main()
{
    use mciSendString();
    mciSendString("play 1",NULL,0,NULL);
system("pause");
}

??

erm i tried to used the code u gave earlier but i got error. Iam using visual studio 2008.

I tried the code written above, exactly the same thing, but im still getting a linker error :

unresolved external symbol __imp__mciSendStringA@16 referenced in function _main

can anyone help me with that ???
i added the winmm.lib in project > porperties > linker > additional library directories
note that im using Visual Studio 2005

thank u