Menu

Thread For Anyone Needing Help With wav files

2007-10-05
2012-09-26
  • Martian Man

    Martian Man - 2007-10-05

    Hello Everyone, I'm posting this thread for anyone who needs help playing .wav files using the PlaySound() function.
    Here's the correct format:

    include <windows.h>

    int main ()
    {
    PlaySound("Path to your .wav file", NULL, SND_SYNC | SND_FILENAME);
    }
    //This will play the wave sound; here's another example:

    PlaySound("C:\Documents and Settings\Your Account\Desktop\YourWave.wav, NULL, SND_SYNC | SND_FILENAME);
    //(Assuming the file name is YourWave.wav and it is on your desktop.)

    Note: If you didn't know, you must use either the double forward slash (\) or a backslash (/) between folders.
    Also if you want to stop the currently playing wave file you can say:

    PlaySound(NULL, NULL, SND_SYNC);
    //I'm not exactly too sure about the stopping function, but I do know the string that points to the file MUST be NULL.

    PLEASE REMEMBER THIS ALSO:

    A TON OF PEOPLE INCLUDING MYSELF USED TO GET CONFUSED WHEN THE CODE POSTED DIDN'T WORK BECAUSE THE ERROR MESSAGE CAME UP: undefined reference to PlaySound@12.

    THIS MEANS THAT YOU MUST INCLUDE THE STATIC LIBRARY libwinmm.a OTHERWISE YOU WILL GET THE ERROR I MENTIONED. TO ADD THE LIBRARY TO YOUR PROJECT:
    1. Right click on the name of your project in the left pane.
    2. From the drop-down menu, choose Project Options.
    3. In the project options window click the Paramaters tab.
    4. Click the button add library or object.
    5. In the open window go to the directory C:\Dev-Cpp\lib.
    6. Find the file libwinmm.a and click open.
    7. The library will now be in the window right above the button add library or object.
    8. Close the Project Options window.
    9. Compile and run your program.

    YOUR DONE!

     
    • Osito

      Osito - 2007-10-05

      I did mention that you had to use the linker option -lwinmm in my reply to your original post...

       
    • Wayne Keen

      Wayne Keen - 2007-10-05

      Martian Man - you might want to provide a simple, complete example program with
      the corresponding compile log. Showing the log provides the folks you are trying
      to help with feedback on what the results of their linking etc. look like.

      Wayne

       
    • Anonymous

      Anonymous - 2007-10-05

      With respect I would suggest that this forum is not the right place for this. Apart from teh next couple of days when it is new and active, it will quickly descend the thread list and be forgotten and people will just start asking the same old questions again. That said I don't remember this one being a particularly frequent issue. Start your own blog perhaps.

      The point about linking the export library is a general one not limited to PlaySound, and is already dealr with in the "Read First" thread.

      Now this is nowhere near as funny as the guy who tried to start a thread for anyone needing help of any kind!? ;-)

      Clifford

       
    • BiT

      BiT - 2007-10-05

      The problem with putting this out there so that people can use the search feature to find it is?????...............The only problem with this is that it should have been appended to the original thread.

      http://sourceforge.net/forum/message.php?msg_id=4522998

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.