Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c++ - Play sound on internal speakers and possibility to use old xp api function?

After the release of windows vista the Windows Function Beep plays a beep on your connected speakers instead of the internal one.

Is there anyway to access the old function? Would it be possible by getting hold in an older windows api? Or is there any other way i can make this possible? If so i would like the ability to set both the frequency and duration.

I should mention that I′m actually targeting the windows xp platform.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No. The function is implemented in a Kernel32.dll, which is loaded at runtime from whatever version of the OS you're currently running. Since the code isn't there in either your executable or in a system DLL, you can't run it (don't even think about copying over Kernel32.dll from a different OS version, that's just screaming for trouble).

You can try using MessageBeep instead of Beep, but that gives you less control over the output and will probably still use your sound card instead of the internal

For an interesting history of the MessageBeep function, see Larry Osterman's blog.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...