Thread: Playsound

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    75

    Exclamation Playsound

    can someone help with this error:
    c:\documents and settings\hp_administrator\my documents\visual studio 2005\projects\soundtest\soundtest\sound test.cpp(14) : error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    Can help me understand sound(s) in c++ better.

    Thanks. Thanks. Thanks.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You're trying to pass a ANSI CHAR string to a function that expects UNICODE CHAR string.
    Either use a conversion function to convert between the two, or if you're simply passing a string, you can put L before like L"file_to_play.wav" (instead of "file_to_play.wav").

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Or you can just call PlaySoundA instead.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Most likely, you have unicode set to default in project options. You can change that. There's usually two different versions of each API, one for ANSI and one for UNICODE.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Or learn to write code which is ANSI and UNICODE compatible at the same time by doing say
    PlaySound(TEXT("file.wav")
    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.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Or PlaySound(_T("file.wav"))
    But erm, this is all if you write the file yourself, of course. It won't work with ANSI STRING variables (and vice versa).

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Which is why there is a whole section of MSDN devoted to describing macros, data types and functions for writing code which is compatible with both approaches.

    Try reading it sometime.
    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.

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

    Question Please... help me!!!

    I put the following code... and I donīt know why I got this 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


    And this is the code: ^
    Code:
    #include <windows.h>
    //#include <winmm.lib>
    #include <mmsystem.h>
    #include <conio.h>
    
    using namespace std ;
    
    int main()
    {
    PlaySound(TEXT("prueba.wav"), NULL, SND_ALIAS | SND_APPLICATION);
    return 0 ;
    }
    PLEASE HELP ME!!!

  9. #9
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Quote Originally Posted by Amarina View Post
    I put the following code... and I donīt know why I got this 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


    And this is the code: ^
    Code:
    #include <windows.h>
    //#include <winmm.lib>
    #include <mmsystem.h>
    #include <conio.h>
    
    using namespace std ;
    
    int main()
    {
    PlaySound(TEXT("prueba.wav"), NULL, SND_ALIAS | SND_APPLICATION);
    return 0 ;
    }
    PLEASE HELP ME!!!

    Stop bumping threads. If you want to ask a question, post it yourself.
    Spidey out!

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, 08: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, 07:30 AM