PlaySound

This is a discussion on PlaySound within the C++ Programming forums, part of the General Programming Boards category; my code for PlaySound is like this: Code: #include <mmsystem.h> int main() { PlaySound(L"release\test16bit.wav", NULL, SND_SYNC); return 0; } when ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    14

    PlaySound

    my code for PlaySound is like this:
    Code:
    #include <mmsystem.h> 
    int main() 
    {
    PlaySound(L"release\\test16bit.wav", NULL, SND_SYNC); 
    return 0; 
    }
    when I build it, I always got error like this:
    Please help, I cannot figure out why I alway got this kind of error
    Thank you very much!
    Code:
    BUILD: [01:0000000030:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(73) : error C2146: syntax error : missing ';' before identifier 'MMVERSION'
    BUILD: [01:0000000031:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(89) : error C2146: syntax error : missing ';' before identifier 'ms'
    BUILD: [01:0000000032:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(90) : error C2146: syntax error : missing ';' before identifier 'sample'
    BUILD: [01:0000000033:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(91) : error C2146: syntax error : missing ';' before identifier 'cb'
    BUILD: [01:0000000034:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(92) : error C2146: syntax error : missing ';' before identifier 'ticks'
    BUILD: [01:0000000035:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(97) : error C2146: syntax error : missing ';' before identifier 'hour'
    BUILD: [01:0000000036:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(98) : error C2146: syntax error : missing ';' before identifier 'min'
    BUILD: [01:0000000037:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(99) : error C2146: syntax error : missing ';' before identifier 'sec'
    BUILD: [01:0000000038:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(100) : error C2146: syntax error : missing ';' before identifier 'frame'
    BUILD: [01:0000000039:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(101) : error C2146: syntax error : missing ';' before identifier 'fps'
    BUILD: [01:0000000040:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(102) : error C2146: syntax error : missing ';' before identifier 'dummy'
    BUILD: [01:0000000041:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(104) : error C2146: syntax error : missing ';' before identifier 'pad'
    BUILD: [01:0000000042:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(111) : error C2146: syntax error : missing ';' before identifier 'songptrpos'
    BUILD: [01:0000000043:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(114) : error C2143: syntax error : missing ';' before '*'
    BUILD: [01:0000000044:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(114) : error C2143: syntax error : missing ';' before '*'
    BUILD: [01:0000000045:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(241) : error C2065: 'HDRVR' : undeclared identifier
    BUILD: [01:0000000046:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(254) : error C2146: syntax error : missing ';' before identifier 'dwDCISize'
    BUILD: [01:0000000047:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(255) : error C2146: syntax error : missing ';' before identifier 'lpszDCISectionName'
    BUILD: [01:0000000048:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(256) : error C2146: syntax error : missing ';' before identifier 'lpszDCIAliasName'
    BUILD: [01:0000000049:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(257) : error C2146: syntax error : missing ';' before identifier 'dnDevNode'
    BUILD: [01:0000000050:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(258) : error C2143: syntax error : missing ';' before '*'
    BUILD: [01:0000000051:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(258) : error C2371: 'NEAR' : redefinition; different basic types
    BUILD: [01:0000000053:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(258) : error C2143: syntax error : missing ';' before '*'
    BUILD: [01:0000000054:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(258) : error C2086: 'int FAR' : redefinition
    BUILD: [01:0000000056:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(292) : error C2146: syntax error : missing ';' before identifier 'dwDCISize'
    BUILD: [01:0000000057:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(293) : error C2146: syntax error : missing ';' before identifier 'lpszDCISectionName'
    BUILD: [01:0000000058:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(294) : error C2146: syntax error : missing ';' before identifier 'lpszDCIAliasName'
    BUILD: [01:0000000059:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(295) : error C2143: syntax error : missing ';' before '*'
    BUILD: [01:0000000060:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(295) : error C2371: 'NEAR' : redefinition; different basic types
    BUILD: [01:0000000062:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(295) : error C2143: syntax error : missing ';' before '*'
    BUILD: [01:0000000063:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(295) : error C2086: 'int FAR' : redefinition
    BUILD: [01:0000000065:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(312) : error C2065: 'CALLBACK' : undeclared identifier
    BUILD: [01:0000000066:ERRORE] C:\WINCE600\public\common\sdk\inc\mmsystem.h(312) : error C2065: 'DRIVERPROC' : undeclared identifier

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    include windows.h as well, before mmsystem.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    14
    Thank you!
    It works.
    But it now have this error:

    Code:
    error LNK2019: unresolved external symbol WinMain referenced in function WinMainCRTStartupHelper
    Why it have problem whith helper?
    Thanks!

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    Because you have "int main", meaning your project should be a console project.
    But it seems you created a GUI project, and that starts at WinMain.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    14
    O~
    Could you tell me how I can fix this error?
    I am using window CE to modilfy some audio driver
    I just try to add a subproject under the OS design project to play some sound.

    When I add subproject, I choose WCE application and then an empty subproject.
    Is there anything wrong?
    Thanks!

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    Just search for how to declare WinMain(), and use that declaration to replace the one you have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    Actually just declare <Windows.h>

    And include the library: winmm.lib (visual studio) or libwinmm.a (for codeblocks/devcpp)

    And your wav file will play, but only wav files.
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    14
    Yes. I just want to play that wave file

    what I do for including this library is like the following. is this correct?

    Code:
    #include <windows.h> 
    #include <mmsystem.h> 
    #pragma comment( lib, "winmm" ) 
    int main() 
    {
    PlaySound(L"release\\test16bit.wav", NULL, SND_SYNC); 
    return 0; 
    }
    But i still get that link error.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    Only if you use Visual C++ (Visual Studio). In that it's called winmm.lib

    If you use Dev-Cpp , go into project options and add the library (it should be in C:\MingW\lib)
    it's called libwinmm.a

    If you use CodeBlocks, go to compiler/linker settings, add the library, it should be in a MinGW\lib folder as well, same name.
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by cangel View Post
    Yes. I just want to play that wave file

    what I do for including this library is like the following. is this correct?

    Code:
    #include <windows.h> 
    #include <mmsystem.h> 
    #pragma comment( lib, "winmm" ) 
    int main() 
    {
    PlaySound(L"release\\test16bit.wav", NULL, SND_SYNC); 
    return 0; 
    }
    But i still get that link error.
    I still don't see the word WinMain anywhere. (That's where Windows applications start, WinMain, not main.)

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    No you don't need WinMain!

    WinMain is only when you have a windows program in which you need to create GUI, read windows messages etc.

    Otherwise int main() and WinMain are pretty much the same, with WinMain you won't see a console window for example, but with main() you will.
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by execute View Post
    No you don't need WinMain!

    Code:

    error LNK2019: unresolved external symbol WinMain referenced in function WinMainCRTStartupHelper
    Then apparently the OP has other problems, or a setting incorrect. I don't know enough about the WinCE SDK to know.

  13. #13
    Registered User
    Join Date
    Sep 2008
    Posts
    14
    Quote Originally Posted by execute View Post
    Only if you use Visual C++ (Visual Studio). In that it's called winmm.lib

    If you use Dev-Cpp , go into project options and add the library (it should be in C:\MingW\lib)
    it's called libwinmm.a

    If you use CodeBlocks, go to compiler/linker settings, add the library, it should be in a MinGW\lib folder as well, same name.
    Yes... I use visual studio 2005

  14. #14
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    If you create a Win32 project in Visual Studio and do not use WinMain, then the program will not compile.

  15. #15
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Question Please help me!!

    I PUT THE FOLLOWING CODE TO PLAY SOUNDS... BUT I GOT 1 ERROR... PLEASE HELP ME!!!

    Code:
    #include <windows.h>
    //#include <winmm.lib>
    #include <mmsystem.h>
    #include <conio.h>
    
    using namespace std ;
    
    int main()
    {
    PlaySound(TEXT("test.wav"), NULL, SND_ALIAS | SND_APPLICATION);
    return 0 ;
    }
    THIS IS THE ERROR!!!

    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\Makefile.win"
    Executing make...
    make.exe -f "C:\Dev-Cpp\Makefile.win" all
    g++.exe -c "sonidos 3.cpp" -o "sonidos 3.o" -nostdlib

    g++.exe "sonidos 3.o" -o "sonidos3.exe" -mwindows winmm.lib -lobjc -nostdlib

    g++.exe: winmm.lib: No such file or directory

    make.exe: *** [sonidos3.exe] Error 1

    Execution terminated



    PLEASE HELP ME!!!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound doesn't play when called!
    By Queatrix in forum Windows Programming
    Replies: 7
    Last Post: 03-03-2006, 07:02 PM
  2. PlaySound error
    By Shadow12345 in forum Windows Programming
    Replies: 5
    Last Post: 10-02-2002, 07:10 AM
  3. PlaySound function & Console App
    By GaPe in forum Windows Programming
    Replies: 2
    Last Post: 06-26-2002, 12:25 PM
  4. about playsound()
    By Sekti in forum C++ Programming
    Replies: 0
    Last Post: 04-08-2002, 05:29 PM
  5. PlaySound();
    By tHaPuTeR in forum Windows Programming
    Replies: 2
    Last Post: 03-11-2002, 06:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21