PlaySound message saying File format not recognized Please help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aravind12345
    New Member
    • Jan 2014
    • 22

    PlaySound message saying File format not recognized Please help me

    I am getting a message from the palysound function it says File format not recognized i have linked the the compiler (i.e. dev c++) to the sound so if someone can help me i will be thank full



    Code:
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <windows.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int m, s,h;
    	 cout << " This is a COUNTDOWN TIMER " << endl;
    	 cout << "Enter hours here" << endl;
    	 cin >> h;
    	 cout << "Enter minutes here " << endl;
    	 cin >> m;
    	 cout << "Enter seconds here" << endl;
    	 cin >> s;
    	 cout << "Press any key to start" << endl;
    	 getch();
    	 cout << " A COUNTDOWN TIMER" << endl;
    	 cout << "time remaining" << endl;
    	 cout << "H : " << h << "M : " << m << " S : " << s << endl;
    	 for (int hour = h; hour >= 0; hour--)
    	 {
    		 for (int min = m; min >= 0 ; min--)
    		 {
    			 if ( min == 0 && h > 0)
    				 m = 59;
    			for (int sec = s; sec >= 0; sec--)
    			{
    				if ( sec == 0 )
    					s = 59;
    				Sleep(750);
    				system("cls");
    				cout << hour << " :hours " << min << " :mins " << sec << " :secs"  << endl;
                    
    			}
    		 } cout << "Timer done press. any key to exit" << endl;
              PlaySound("C:\\Users\\PV\\Desktop\\shortcuts\alaram.wav", NULL, SND_ASYNC);
    	 getch();
    	 }
    	Sleep(1000);
    	
    	return 0;
        system("PAUSE");
       
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I think your path is incorrect:

    Code:
     PlaySound("C:\\Users\\PV\\Desktop\\shortcuts\alaram.wav", NULL, SND_ASYNC);
    You are missing a slash:
    Code:
     PlaySound("C:\\Users\\PV\\Desktop\\shortcuts[B]\[/B]\alaram.wav", NULL, SND_ASYNC);

    Comment

    • aravind12345
      New Member
      • Jan 2014
      • 22

      #3
      weaknessforcats it is giving me the same message
      Code:
      (file format not recognized   ld returned 1 exit status   *** [Project1.exe] Error 1 )
      so is there any thing i can change or add any other header file please help me i really need this to be done.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This is the function prototype for PlaySound:

        Code:
        BOOL PlaySound(
          LPCTSTR pszSound,
          HMODULE hmod,
          DWORD fdwSound
        );
        Here you see that the path to your sound file must be an LPCTSTR (long-pointer-to-a-constant-TCHAR-string). An ASCII string in a pair of quotes is not an LPCTSTR.

        Microsoft is strictly Unicode represented by 16-bit chars of the type wchar_t. Old programs used 8-bit chars, like in your ASCII string. Wide characters are handled by PlaySoundW and ASCII characters are handled by PlaySoundA.

        PlaySound is really a macro that evaluates to PlaySoundA or PlaySoundW based on whether your project is Unicode or not.

        You might change your call to PlaySoundA and see if you get your sound. If you do, then you need to read up on the TCHAR rules of Microsoft.

        This will get you started: http://msdn.microsoft.com/en-us/library/c426s321.aspx

        Comment

        Working...