playsound() error

iv tried adding sound about 20 different ways and non of them work.
this is the code:
1
2
3
4
5
6
7
#include <windows.h>
#include <mmsystem.h>
int main()
{
PlaySound(TEXT("bomb.wav"), NULL, SND_FILENAME);
return 0;
}

1 way i tried (as instructed on these forums) to link to winmm.lib and when i did that is came up with an error saying it cant find winmm.lib.

Another way i tried was without linking and it says:

undefinded reference to 'PlaySoundA@12'

I also tried changing the code in different ways...
1
2
3
4
5
6
7
#include <windows.h>
#include <mmsystem.h>
int main()
{
PlaySound("bomb.wav", NULL, SND_FILENAME);
return 0;
}

and
1
2
3
4
5
6
7
8
#include <windows.h>
#include <mmsystem.h>
#include <winmm.lib>
int main()
{
PlaySound(TEXT("bomb.wav"), NULL, SND_FILENAME);
return 0;
}

(comes up that there is no such file or directory called winmm.lib)


I have tried all the different ways on 2 different editors.(Code::Blocks & Dev C++)

can someone explain why it wont work and please dont just send me to a link somewhere else?
You do NOT #include <winmm.lib>

You LINK to winmm.lib in your additional dependencies configuration, whatever that is for Dec C++ or Code::Blocks, as I don't use either one.

In VS it's under Properties | Linker | Input | Additional Dependencies

Once there, you add winmm.lib as an additional dependency.
Last edited on
that means winmm.lib file in your library is missing you can either re-install the program or just download winmm.lib and paste in correct directory.
but there is another option for you. i.e. if you load the dll dynamically then you don't need library files. so try loading winmm.dll dynamically this might help you.
also make note that PlaySound cannot play sound file of large size may be greater than 1mb (i guess) in this case you can use function mciSendString........

give a try and if you couldn't do it reply to the post and i'm gonna help you....
For Code::Blocks, go to Project/Build Options/Linker settings and add winmm to the link libraries (no .lib at the end!).
Topic archived. No new replies allowed.