Emitting a beep on the internal speaker

Hi all,
I'm looking for a way to emit a beep on the internal speaker no matter
what the multimedia configuration is (sound card installed or not).
Under Windows NT, there is Beep() that does the job nicely, but under
Win95/98, it doesn't work the same.
Is there a way to achieve this on all Windows platforms?
jrepettoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
Hi jrepetto,

Try MessageBeep( -1 );

ZOPPO
0
jrepettoAuthor Commented:
Unfortunately, MessageBeep(-1) only produces a small click, not a beep ...

Jean-Claude
0
BudVVeezerCommented:
Beep(Tone, Length);
Tone is the number of hertz(what KIND of noise) and Length is how long you want it to play.  If the computer does NOT have a sound card, it does the standard beep.

~Aaron

The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes.

BOOL Beep( DWORD dwFreq,
 // sound frequency, in hertz
 
DWORD dwDuration
 // sound duration, in milliseconds
 
);
 


Parameters
dwFreq

Windows NT:

Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).

Windows 95:

The parameter is ignored.

dwDuration

Windows NT:

Specifies the duration, in milliseconds, of the sound.

Windows 95:

The parameter is ignored.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Windows 95:

The Beep function ignores the dwFreq and dwDuration parameters. On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

ZoppoCommented:
Hey BudWeezer, re-read the question carefully:

>I'm looking for a way to emit a beep on the internal speaker no matter
>what the multimedia configuration is (sound card installed or not).

So, just a copy of MSDN description for Beep is not a solution!


jrepetto: Unfortunately I have neither Win9x nor a soundcard, so I think I can't help you out of this :(
0
jrepettoAuthor Commented:
I agree with Zoppo's comment. I am looking for a solution for Win95/98.

Jean-Claude
0
PacmanCommented:
I have the same problem. The Microsofties seem to assume that each PC has a soundcard with connected speakers ...
0
BudVVeezerCommented:
Yes, but keep in mind, it WILL work for a computer with speakers or without.  I guess I don't understand why it must be on just the internal speaker...

~Aaron
0
BudVVeezerCommented:
oops, I meant sound card instead of speakers.  ;-)
0
Alisher_NCommented:
what about
for j1 := 1 to 1000 do MessageBeep( $FFFFFFFF );

?

;-)

0
PacmanCommented:
Alisher_N

who knows what MessageBeep() does in future versions of windows.
Maybe you get 1000 beeps ... 15 minutes beep beep beep beep ...
0
Alisher_NCommented:
when working with windows you never know what will happen 'in next version', you even can not be sure 100% how it works in your current version ;-), if you want to have always_stable, always_clean, always_reliable code move to anoither OS ;-)))

0
BudVVeezerCommented:
I would tend to agree, I hear BeOS is going to be killer.  =)  I seem to recall something like SysBeep or something pretty close to it a LONG time ago...  One thing you might try is a LOW LEVEL beep, from assembly.  If there aren't any API to make the beep, ya get to do it yourself.  ;-P

~Aaron
0
PacmanCommented:
maybe you can buy a ActiveX-Control from Micro$oft which beeps for you ...
: )
0
ZoppoCommented:
can you hear the correct beep when you do following:

open a dosbox and enter:
echo [CTRL-G][ENTER]

if so, you could write a char 0x07 to a console's standard output handle...

ZOPPO
0
jrepettoAuthor Commented:
In a dosbox, when I enter [CTRL-G] [ENTER], I get the message : Bad command or file name :-)

But if I fill the command line until the buffer overflow, I can hear the windows standard sound, like the Beep() function.

0
ZoppoCommented:
echo (followed by CTRL+G followed by ENTER)
0
ScottyDawgCommented:
Zoppo, I had a look at this a while ago and according to MS docs ascii 0x07 (amongst others) isn't a supported character *sigh*. I remember it used to work on Win 3.1 though....
0
ZoppoCommented:
It also works in NT console apps ...
0
FausticCommented:
This seems a little late to mention, but did you try the other MessageBeep() values that are possible?

MB_ICONASTERISK
MB_ICONEXCLAMATION
MB_ICONHAND
MB_ICONQUESTION
MB_OK ( <- system default )

You mentioned that you do get the normal beep through your speaker in some cases.  Those instances are probably the result of one of the above cases.

When it comes to versatility this excerpt from the MessageBeep reference says it all:
"If it cannot play the specified alert sound, MessageBeep attempts to play the system default sound. If it cannot play the system default sound, the function produces a standard beep sound through the computer speaker."

The reference does mention that:
"The user can disable the warning beep by using the Control Panel Sound application."  So there's at least one "multimedia configuration" that you won't be able to handle.
0
Alisher_NCommented:
'system default' is $FFFFFFFF or -1 we have discussed before....

0
BudVVeezerCommented:
And there was a reason I said use MessageBeep...so your answer is nothing new...

~Aaron
0
FausticCommented:
From win.h

#define MB_OK      0  // not 0xFFFFFFFF

Complete quote:

Value              Sound
0xFFFFFFFF      Standard beep using the computer speaker
MB_ICONASTERISK      SystemAsterisk
MB_ICONEXCLAMATION      SystemExclamation
MB_ICONHAND      SystemHand
MB_ICONQUESTION      SystemQuestion
MB_OK              SystemDefault

If he hasn't tried the other options then there is something new.

0
jrepettoAuthor Commented:
Adjusted points to 200
0
jrepettoAuthor Commented:
I think you didn't understand exactly what I want to do. There are lots of PCs with sound cards but no loudspeakers connected to them. That is why I want to send a beep to the internal loudspeaker, even if there is a sound card installed.
0
BudVVeezerCommented:
Yeah, which MessageBeep does...  If there aren't any speakers attached to the computer, then it will send it to the internal speaker.  And I guess I still don't understand why you would always want it to go to the internal, even if there are external speakers.  Please, keep in mind, the answer you don't want to hear is still an answer, and we've had numerous people come up with the same thing for you...  I think you either get to use MessageBeep, or like I said earlier, come up with your own low level function that does it.  There aren't any more clear ways to do it...  Sorry!

~Aaron
0
jrepettoAuthor Commented:
BudWeezer wrote:
"If there aren't any speakers attached to the computer, then it will send it to the internal speaker".
I don't agree, since Windows doesn't know if there are external speakers attached or not ...

But I agree on your last sentence, I think there is no simple way to do that, except writing a low level function.
0
BudVVeezerCommented:
Windows does too know if there are speakers attached.  If there are speakers attached, the the multimedia functions will automatically take the information from the drivers to determine where to send the sound.  If there are external speakers plugged into the computer, then when the drivers send the request to the external speakers, the sound goes there.  If the request fails, then it defaults to the internal speaker.  If Windows didn't know the speakers were there, NO sound would go to the external speakers...  As for writing a low level functions, best of luck....well beyond my scope.  ;-)

~Aaron
0
Alisher_NCommented:
hey, budweezer!
you are mixing 'sound card' and 'extrenal speakers' !
if you don't know the difference just post new question for.... let's say 200 points we are ready to explain that ;-))

0
BudVVeezerCommented:
hey Alisher_N, I DO know the difference between the two, but do YOU know how the one interfaces with the other?  ;-/  If you don't, I'll explain it to you for free.  Here's a hint, without the one, the other does work too well.  ;-)  And the neat thing is, one polls the status of the other, and when it doesn't find it, it will poll a different device, say possibly the internal speaker.  Hence the reason why MessageBeep will go with whatever happens to be around.  If you have a computer with external speakers, but you want all your beeps through the internal speaker, not only are you off your rocker, but you can specify it in the multimedia control panel under preferred device.  All that for free.  =P

~Aaron
0
Alisher_NCommented:
I am talking about usual speakers, connected via 'Audio Out' socket on sound card (with a small round plug ;) and NONE of known to me sound cards can detect if SUCH speakers (or headphones) connected to sound card or no. The card just outputs the singnal, but can you hear it or no - it is problem of user.

yes, you can do whatever you want with multimedia configurations, but with sound cards, NOT with external speakers ;-//

if you are talking about some super-puper vacuum-proof advanced quadro Dolby-surround multimedia system connected via USB (or other proprietary interface of your particular sound card) wich costs $XXXX that might be a true, but I thought we are talking about average user here...

0
BudVVeezerCommented:
::grins::ya know what, I was wrong, and I admit it, and I sure shouldn't have been as cocky as I was.  Lack of sleep prohibited my brain from working properly, and I apologize.  But, assuming my brain has started up again(I'm still not sure it has), where would MessageBeep go wrong?  I guess I find it odd that a beep MUST go to an internal speaker if there are externals attached...  And now that I think about it, how WOULD MessageBeep know that no external is attached?  Ya know how it says if no external then will default to internal.  There MUST be a way of polling that little round plug.  ;-)  Ah well...I'll keep digging in my resources and see if I can't find something else.

~Aaron
0
Alisher_NCommented:
;-))
....but you was so confident, that I even started to think that I probably behind the technical progress ;-)

ok, it happens...

0
FausticCommented:
Well, if it's programming ONLY the internal speaker you want, you can use the sound routines in the Snippets distribution zip file.  It's low level and you'll have to set the tone of the beep by trial and error.  All the files you need are at:

ftp://ftp.snippets.org/snpd9707.zip

or just go their web site at:

http://www.snippets.org


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.