How to compile a c++ console application which uses the PlaySound function?

149 views Asked by At

This is what I compile:

#include <iostream>
#include <Windows.h>
#include <mmsystem.h>

int main() {
PlaySound(TEXT("bineba.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
}

The code is written in Visual Basic 2013 Express. The sound plays when I use "Start Without Debugging" but if I run the ".exe" file which I compiled it does not. Also, I've included the winmm.lib file in the project properties and that works fine. How can I make it so the sound plays even when I run the ".exe" file?

1

There are 1 answers

0
Kelm On BEST ANSWER

The reason is most likely the location of the sound file relative to the directory the .exe is ran in by the VS (doesn't have to be the same directory the executable resides in). In this case, try copying the sound file to the .exe file's directory.