PlaySound

Started by
2 comments, last by mike74 5 months, 1 week ago

I wrote some code in C++ to play a sound:

#include <Windows.h>
#include <iostream>

int main() {
BOOL result = PlaySound(TEXT("C:\\Windows\\Media\\tada.wav"), NULL, SND_FILENAME | SND_ASYNC);
if (result == TRUE) {
 std::cout << "Sound played successfully!" << std::endl;
}
else {
 std::cout << "Error playing sound." << std::endl;
}
return 0;
}

It says it played successfully, but I don't hear anything. Anyone know what's wrong?

Thanks.

Mike C.http://www.coolgroups.com/zoomer/http://www.coolgroups.com/ez/
Advertisement

I'd guess it's because your program exits before it can play the sound. Try removing the “SND_ASYNC” flag so that it waits for the sound to play before exiting.

@Aressera Okay, it works now. Thanks a lot.

Mike C.http://www.coolgroups.com/zoomer/http://www.coolgroups.com/ez/

This topic is closed to new replies.

Advertisement