1

I've been trying to play a .M4A file with PlaySound(); in code::blocks (C++). I looked on several websites and found nothing that really helped me. I probably made a REALLY small mistake, but if anybody can help, that would be great.

#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main()
{
    PlaySound("wt.M4A", NULL, SND_ASYNC | SND_FILENAME);
    Beep(1000,1000);
    getch(); // wait
    return 0;
}

I expect the code to play an audio clip, then play a beeping noise, and I have tried removing beep();

instead, I get an error that says :

Undefined reference to PlaySoundW@12

thanks!

1 Answers1

1

You must link against winmm.lib / libwinmm.a in order to have PlaySoundA/PlaySoundW functions.

Also, be careful with unicode: you are calling PlaySoundW but you pass an ANSI string. Make sure to call PlaySoundA or use unicode strings. To use unicode strings, there is the TEXT macro and you must #define UNICODE or -DUNICODE command-line option.

QuentinC
  • 12,311
  • 4
  • 24
  • 37