Beep() does not work!

M

MrNobody

I am trying to find a way to make my system beep and multiple articles I
google explain a method using P/Invoke like this:

#region Win32

[DllImport("Kernel32.dll")]
static extern bool Beep(
uint dwFreq, uint dwDuration
);

#endregion


Beep(1000, 1000);

But no sound is produced.

I can play any MP3, WAV or MIDI file on the same system and hear the music
but I cannot hear anything coming from this Beep() function.

Any idea what may be wrong?
 
J

Jeff Gaines

[DllImport("Kernel32.dll")]
static extern bool Beep(
uint dwFreq, uint dwDuration
);

Are you sure this is correct, Beep isn't in the help file. I use:

// MessageBeep
[DllImport("user32.dll")]
public static extern int MessageBeep(int wType);
 
M

MrNobody

HI Jeff, thanks for the reply!

your MessageBeep does indeed produce a sound! But is there a way to alter
it's frequency?

thanks!

Jeff Gaines said:
[DllImport("Kernel32.dll")]
static extern bool Beep(
uint dwFreq, uint dwDuration
);

Are you sure this is correct, Beep isn't in the help file. I use:

// MessageBeep
[DllImport("user32.dll")]
public static extern int MessageBeep(int wType);
 
M

MrNobody

Thanks for the reply sloan!

That is strange... Console.Beep produces no noise either...

Is it possible perhaps these beep function utilize a motherboard speaker
instead of the audio card? This may explain why I get no sound...

sloan said:
Console.Beep for later frameworks.

Also see:
http://blogs.msdn.com/brada/archive/2004/06/03/148142.aspx


MrNobody said:
I am trying to find a way to make my system beep and multiple articles I
google explain a method using P/Invoke like this:

#region Win32

[DllImport("Kernel32.dll")]
static extern bool Beep(
uint dwFreq, uint dwDuration
);

#endregion


Beep(1000, 1000);

But no sound is produced.

I can play any MP3, WAV or MIDI file on the same system and hear the music
but I cannot hear anything coming from this Beep() function.

Any idea what may be wrong?
 
F

Family Tree Mike

MrNobody said:
I am trying to find a way to make my system beep and multiple articles I
google explain a method using P/Invoke like this:

#region Win32

[DllImport("Kernel32.dll")]
static extern bool Beep(
uint dwFreq, uint dwDuration
);

#endregion


Beep(1000, 1000);

But no sound is produced.

I can play any MP3, WAV or MIDI file on the same system and hear the music
but I cannot hear anything coming from this Beep() function.

Any idea what may be wrong?


When I used the declaration from
http://www.pinvoke.net/default.aspx/kernel32/Beep.html, it worked fine for
me.

The declaration they use is:
[DllImport("kernel32.dll", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool Beep(uint dwFreq, uint dwDuration);
 
F

Family Tree Mike

Michael D. Ober said:
The API Beep functions don't support pitch options.

Mike.

MrNobody said:
HI Jeff, thanks for the reply!

your MessageBeep does indeed produce a sound! But is there a way to alter
it's frequency?

thanks!

Jeff Gaines said:
On 21/02/2009 in message

[DllImport("Kernel32.dll")]
static extern bool Beep(
uint dwFreq, uint dwDuration
);

Are you sure this is correct, Beep isn't in the help file. I use:

// MessageBeep
[DllImport("user32.dll")]
public static extern int MessageBeep(int wType);


The call he is using does change pitch for me. I never knew about this one.
 
W

William Stacey

Try
System.Media.SystemSounds.Beep.Play();

I think console.beep does use the internal speaker which may not be enabled
or working.
 
M

Mick Doherty

MrNobody said:
That is strange... Console.Beep produces no noise either...

Is it possible perhaps these beep function utilize a motherboard speaker
instead of the audio card? This may explain why I get no sound...

Beep plays a tone through a PC (motherboard) speaker.
MessageBeep plays a wav sound through the soundcard.
 
M

MrNobody

Yes,
System.Media.SystemSounds.Beep.Play();
works as well as the MessageBeep, which means it is going through soundcard
like I want, but unfortunately like MessageBeep I cannot set the frequency.

So is it safe to conclude it is not possible to send a tone through the
soundcard with variable frequency?

Thanks for all your input guys, I greatly appreciate it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top