locked
Win32 Play sound RRS feed

  • Question

  • bool Win64Sound::PlayIt() {
        //return !!PlaySoundW(WideStringSoundFileName.c_str(), NULL, SND_FILENAME );
        return !!sndPlaySound(StringSoundFileName).c_str(),SND_ASYNC);
    }

    I have tested this member function using PlaySoundW() and had no problems, but sndPlaySound() does not produce any sound. I am linking against -lwinmm -mwindows

    I am using a Win 8.1 machine.

    Anyone here knows what could be the problem?

    Saturday, August 19, 2017 12:24 PM

All replies

  • Well, besides the obvious compiler error in the sndPlaySound line, you have SND_ASYNC for sndPlaySound but not for PlaySound, does adding SND_ASYNC to PlaySound, or removing it from sndPlaySound make any difference?

    Otherwise, the only other things to look at is to make sure that the StringSoundFileName has the correct path, since it is a different variable to WideStringSoundFileName that PlaySound uses.

    Anyway, sndPlaySound is only being maintained for backwards compatibility. If you can, I would suggest you change everything over to PlaySound anyway. What's more, both of these have basically been superseded by WASAPI.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Edited by Darran Rowe Saturday, August 19, 2017 3:57 PM
    • Proposed as answer by Baron Bi Monday, August 21, 2017 5:34 AM
    Saturday, August 19, 2017 3:56 PM