title: C++ Play audio in Windows
body: <p>I'm currently working on a project and I need to play a sound file (which is actually a video but I only want to play the sound). Someone told me I could use a PlaySound function but it's currently not working (it plays this sound when I run instead of the file I wanted <a href="https://dl.dropboxusercontent.com/u/45453297/Windows%20Background.wav" rel="nofollow">https://dl.dropboxusercontent.com/u/45453297/Windows%20Background.wav</a>)</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
      PlaySound(TEXT("C:\\Users\\Ricardo\\Documents\\Visual Studio 2013\\Projects\\SomEVideo\\SomEVideo\\KinectAudio-02-23-32.wav"), NULL, SND_FILENAME);
      return 0;
  }
  </code></pre>
  
  <p>On stdafx.h I included these headers:</p>
  
  <pre><code>#include "windows.h"
  #include "mmsystem.h"
  </code></pre>
  
  <p>I also linked winmm.lib on my project so I don't get no unresolved problems.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>After been told that the path was wrong, I changed the file name to "t.wav" and placed it in the hard drive root to avoid typing errors. I also tried PlaySounDW and play it like a resource. Here's what I'v got so Far with no success:</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
      PlaySoundW(TEXT("C:/t.wav"), NULL, SND_FILENAME); //GetLastError returns 0
      PlaySoundW(TEXT("C:\\t.wav"), NULL, SND_FILENAME); //GetLastError returns 0
      PlaySoundW(TEXT("t.wav"), NULL, SND_FILENAME); //GetLastError returns 0
  
      PlaySound(TEXT("C:/t.wav"), NULL, SND_FILENAME); //GetLastError returns 0
      PlaySound(TEXT("C:\\t.wav"), NULL, SND_FILENAME); //GetLastError returns 0
      PlaySound(TEXT("t.wav"), NULL, SND_FILENAME); //GetLastError returns 0
  
      PlaySoundW(MAKEINTRESOURCE("C:/t.wav"), GetModuleHandle(NULL), SND_RESOURCE); //GetLastError returns 1813
      PlaySoundW(MAKEINTRESOURCE("C:\\t.wav"), GetModuleHandle(NULL), SND_RESOURCE); //GetLastError returns 1813
      PlaySoundW(MAKEINTRESOURCE("t.wav"), GetModuleHandle(NULL), SND_RESOURCE); //GetLastError returns 1813
  
      PlaySound(MAKEINTRESOURCE("C:/t.wav"), GetModuleHandle(NULL), SND_RESOURCE); //GetLastError returns 1813
      PlaySound(MAKEINTRESOURCE("C:\\t.wav"), GetModuleHandle(NULL), SND_RESOURCE); //GetLastError returns 1813
      PlaySound(MAKEINTRESOURCE("t.wav"), GetModuleHandle(NULL), SND_RESOURCE); //GetLastError returns 1813
  
      return 0;
  }
  </code></pre>