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

using namespace std;

int main()
{
    PlaySound ("test.wav",NULL, SND_SYNC);
    return 0;
}

errors :

error

error

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
D XGamer
  • 9
  • 2
  • I don't really know how `PlaySound` works, but if it requires a relative path, then I assume the executable must be located in the same directory as `test.wav`. Otherwise, you may want to provide the working directory to the executable and a relative path, or the absolute path to the file. – RL-S Nov 05 '21 at 14:22
  • The second message says that there is no executable. The first message says that it cannot create the executable because of the error message stated. Did you google the error message? I downvoted because you obviously did not even try to google the error message. There are a lot of solutions available. – mch Nov 05 '21 at 14:23
  • try `L"test.wav"` you're using unicode APIs and those require wide strings. – Mgetz Nov 05 '21 at 14:26

1 Answers1

2

Your project is configured to use Unicode version of Windows API, but your source files are in ASCII.

To solve this problem without messing with configuration, simply specify the string constants to be Unicode like this:

PlaySound (L"test.wav",NULL, SND_SYNC);

Notice the L before the string constant.

Alternatively, you could call the ASCII version of the API directly:

PlaySoundA("test.wav",NULL, SND_SYNC);

It is the same function name but ends with an A. This is not recommended however, for compatibility reasons.

Lev M.
  • 6,088
  • 1
  • 10
  • 23
  • Technically, that's not correct. If you're using the generic-text mapping, you'll have to use the `TEXT` macro. Either one of the following is correct: `PlaySoundW(L"...", ...)`, `PlaySound(TEXT("..."), ...)`, or `PlaySoundA("...", ...)`. Contrary to that, `PlaySound(L"...", ...)` is just as wrong as the code in question, and it fails in the same way, depending on project settings. – IInspectable Nov 05 '21 at 15:17