0

I have tried the Beep() function:

#include <iostream>
#include <windows.h>
using namespace std;

int main(){
    Beep(500,1000);
    Sleep(10000);

    return 0;
}

But it doesn't seem to produce any sound.

I tried printing out a \a characters, but it just makes Windows 10 play a default sound:

#include <iostream>
#include <windows.h>
using namespace std;

int main(){
    cout << '\a';

    return 0;
}

Any help, please!

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Handy reading: [MSDN page for `Beep`](https://learn.microsoft.com/en-us/windows/win32/api/utilapiset/nf-utilapiset-beep). Of particular interest may be the section on the return value. – user4581301 May 26 '22 at 18:59
  • 1
    What kind of sound do you want to produce and for what purpose ? `Beep()` is a very old function which is not reliable anymore with modern computers. –  May 26 '22 at 19:05
  • @user4581301 I just tried to see the return value and it is nonzero, so the program and the Beep command should be running correctly so the problem is somewhere else. – Момчил Андонов May 26 '22 at 19:20
  • Groovy. Always good to eliminate the low-hanging fruit. – user4581301 May 26 '22 at 19:41
  • Interesting. I always use this function to test a DLL export calling utility I made and it always works. Maybe its the `Sleep` which causes this. – demberto May 26 '22 at 20:04
  • Does this answer your question? [C - printf("\a") won't sound an alert](https://stackoverflow.com/questions/46728477/c-printf-a-wont-sound-an-alert) – Trishant Pahwa May 26 '22 at 20:39
  • https://stackoverflow.com/questions/46728477/c-printf-a-wont-sound-an-alert – Trishant Pahwa May 26 '22 at 20:39
  • 1
    @Sedenion `Beep()` **was** a very old function, but quoting the documentation page (linked in the first comment above): "_In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client._" So, it seems that `Beep()` is now a rather new, completely reworked, function. – heap underrun May 26 '22 at 20:57
  • Thank you, everyone. I don't know what happened, but suddenly it worked. And I am very happy that I learned a thing or two from your responses. – Момчил Андонов May 30 '22 at 14:26

0 Answers0