I have the following code:
#include <windows.h>
#include <stdio.h>
int main(void)
{
Beep(523, 500);
Sleep(1000);
return 0;
}
I am compiling it using MinGW with Dev-C++. My problem is that I can't hear anything, although I don't get an error. I have Windows 7. Any ideas?
Turn your speakers on. If they're already on, turn up the volume. If you don't have speakers and a sound card installed on your computer, then get some and install them, then try running the program again.
All of these things are required to hear anything from the Beep
function on Windows 7. It no longer plays sound from the built-in hardware system speaker. Instead, the sound is passed to the default sound device for your user session. In a standard local user session, that would be your sound card. The documentation explains this important detail in the "Remarks" section:
A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The
Beep
function was written specifically to emit a beep on that piece of hardware.On these older systems, muting and volume controls have no effect on
Beep
; you would still hear the tone. To silence the tone, you used the following commands:net stop beep sc config beep start= disabled
Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that
Beep
did not work on all computers without the chip. This was okay because most developers had moved on to calling theMessageBeep
function that uses whatever is the default sound device instead of the 8254 chip.Eventually because of the lack of hardware to communicate with, support for
Beep
was dropped in Windows Vista and Windows XP 64-Bit Edition.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With