CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2009
    Posts
    12

    sndPlaySound Wont play

    Hi
    Im back =)

    Well I was trying to play a .wav file from my app path with

    PlaySound("BELLS.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);

    and tryed

    sndPlaySound ("BELLS.wav",SND_LOOP|SND_ASYNC);

    the PlaySound wont do nothing but the sndPlaySound will make beeps like the is not in the apppath witch it was

    So.... I gave up and moved on an tryed playing it from the resources.
    I added the resources an the BEELS.wav to the resources
    An used this code to try to play it

    sndPlaySound(MAKEINTRESOURCE(IDR_WAVE1), SND_RESOURCE |SND_ASYNC );

    and tryed

    PlaySound(MAKEINTRESOURCE(IDR_WAVE1), SND_RESOURCE |SND_ASYNC );

    and tryed

    HANDLE sndBoing;
    HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_WAVE1), "WAVE");
    hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_WAVE1), "WAVE");
    sndBoing = LoadResource(hInstance, hResInfo);
    const char* sndRes = (const char*)LockResource(sndBoing);
    PlaySound(sndRes, SND_MEMORY|SND_ASYNC|SND_NODEFAULT);
    UnlockResource(sndRes);

    But none of the worked

    Here is a screen shot of my scr

    http://img19.picoodle.com/img/img19/...em_040fb11.jpg

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: sndPlaySound Wont play

    Quote Originally Posted by rentagoth View Post
    I was trying to play a .wav file from my app path with

    PlaySound("BELLS.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
    Well, it is obvious that the "current working directory" might be not the same as the one containing "BELLS.wav" file.
    You have to pass in the full pathe name to the PlaySound call.


    Quote Originally Posted by rentagoth View Post
    An used this code to try to play it

    sndPlaySound(MAKEINTRESOURCE(IDR_WAVE1), SND_RESOURCE |SND_ASYNC );
    1. Of course, it is wrong. And it cannot just compile!
    You forgot the second parameter that must be the handle to the executable file that contains the resource to be loaded.
    The correct call should look like:
    Code:
    PlaySound(MAKEINTRESOURCE(IDR_WAVE1), AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
    2. Is the IDR_WAVE1 correct ID? Or it looks like the text "IDR_WAVE1"?
    In latter case you must not use MAKEINTRESOURCE macro - just:
    Code:
    PlaySound("IDR_WAVE1", AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2009
    Posts
    12

    Re: sndPlaySound Wont play

    Quote Originally Posted by VictorN View Post
    Well, it is obvious that the "current working directory" might be not the same as the one containing "BELLS.wav" file.
    You have to pass in the full pathe name to the PlaySound call.


    1. Of course, it is wrong. And it cannot just compile!
    You forgot the second parameter that must be the handle to the executable file that contains the resource to be loaded.
    The correct call should look like:
    Code:
    PlaySound(MAKEINTRESOURCE(IDR_WAVE1), AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
    2. Is the IDR_WAVE1 correct ID? Or it looks like the text "IDR_WAVE1"?
    In latter case you must not use MAKEINTRESOURCE macro - just:
    Code:
    PlaySound("IDR_WAVE1", AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
    I tryed that and none of them worked.

    Maybe is me trying to play the sound in my .dll

    Ok playsound will not work in my .dll for nothing
    PlaySound("C:\\BELLS.wav", NULL, SND_FILENAME);

    but this works
    sndPlaySound ("C:\\BELLS.wav",SND_LOOP|SND_ASYNC)

    how do I use sndPlaySound to play a sound from my resources

    Here is was my resource script file looks like
    ////////////////////////////HL2.rs///////////////////////
    // Microsoft Visual C++ generated resource script.
    //
    #include "resource.h"

    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"

    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS

    /////////////////////////////////////////////////////////////////////////////
    // English (U.S.) resources

    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    #pragma code_page(1252)
    #endif //_WIN32

    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //

    1 TEXTINCLUDE
    BEGIN
    "resource.h\0"
    END

    2 TEXTINCLUDE
    BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
    END

    3 TEXTINCLUDE
    BEGIN
    "\r\n"
    "\0"
    END

    #endif // APSTUDIO_INVOKED


    /////////////////////////////////////////////////////////////////////////////
    //
    // WAVE
    //

    IDR_WAVE1 WAVE "BELLS.wav"
    #endif // English (U.S.) resources
    /////////////////////////////////////////////////////////////////////////////



    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //


    /////////////////////////////////////////////////////////////////////////////
    #endif // not APSTUDIO_INVOKED




    here is what my resource.h looks like
    /////////////////////resource.h///////////////////////
    //{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by HL2.rc
    //
    #define IDR_WAVE1 102

    // Next default values for new objects
    //
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE 103
    #define _APS_NEXT_COMMAND_VALUE 40002
    #define _APS_NEXT_CONTROL_VALUE 1001
    #define _APS_NEXT_SYMED_VALUE 101
    #endif
    #endif


    here is what my code looks like
    Im trying to do all this in a .dll not an .exe

    http://img19.picoodle.com/img/img19/...em_040fb11.jpg

    Srry for the slopy post I dont see a code block option on the post

    [code/] [code]
    Last edited by rentagoth; March 23rd, 2009 at 01:33 PM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: sndPlaySound Wont play

    Quote Originally Posted by rentagoth View Post
    ...
    Im trying to do all this in a .dll not an .exe
    What type of dll? Is it an MFC dll or not? If MFC - is it a regular or estension dll?
    How are you using this dll?
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2009
    Posts
    12

    Re: sndPlaySound Wont play

    Quote Originally Posted by VictorN View Post
    What type of dll? Is it an MFC dll or not? If MFC - is it a regular or estension dll?
    How are you using this dll?
    My Use of MFC is set to Use Standard Windows Libraries

  6. #6
    Join Date
    Feb 2009
    Posts
    42

    Re: sndPlaySound Wont play

    And what about:

    PlaySound(_T(".Default"),NULL, SND_APPLICATION|SND_NODEFAULT);

    this will play default bell sound in windows.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: sndPlaySound Wont play

    Quote Originally Posted by rentagoth View Post
    My Use of MFC is set to Use Standard Windows Libraries
    Sorry, but I couldn't understand what you meant.
    Victor Nijegorodov

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: sndPlaySound Wont play

    Quote Originally Posted by rentagoth View Post
    ... Im trying to do all this in a .dll not an .exe
    And would the same code work if you placed it in the exe?
    Victor Nijegorodov

  9. #9
    Join Date
    Mar 2009
    Posts
    12

    Re: sndPlaySound Wont play

    Quote Originally Posted by VictorN View Post
    And would the same code work if you placed it in the exe?
    this is that code that worked in the .exe

    PlaySound("BELLS.WAV", NULL, SND_ASYNC);
    It play the bells.wave from where the .exe is

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: sndPlaySound Wont play

    Quote Originally Posted by rentagoth View Post
    this is that code that worked in the .exe

    PlaySound("BELLS.WAV", NULL, SND_ASYNC);
    It play the bells.wave from where the .exe is
    Well, if this code does work being in exe and does NOT work being in dll then 99.9% that the problem is in your dll.
    Therefore I already asked you but haven't got an answer:
    Quote Originally Posted by VictorN View Post
    What type of dll? Is it an MFC dll or not? If MFC - is it a regular or estension dll?
    How are you using this dll?
    Note, that if it is an MFC regular dll then you have to add
    Code:
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    to the beginning of the exported functions. See MSDN for details
    Victor Nijegorodov

  11. #11
    Join Date
    Mar 2009
    Posts
    12

    Re: sndPlaySound Wont play

    Nvm I just gave up on it
    Thank you for your help =)
    much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured