Playsound

This is a discussion on Playsound within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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
    1,534
    Or you can just call PlaySoundA instead.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 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