Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to turn on/off  the pc speaker in W2K?

Posted on 2002-06-23
7
Medium Priority
?
350 Views
Last Modified: 2010-04-04
Hi all,
This codes work fine with win98, but can't work with Win2000, How to change it? (Please don't just tell me a component, I need the source)


 if BeepOn then        //BeepOn is a logic flag
 begin
 asm
   mov al,3            //turn on the pc speaker
   out $61,al
   mov al,$0B6
   out $43,al
   mov al,200
   out $42,al
   mov al,20
   out $42,al
 end;
 end
 else
 begin
 asm
  mov al,0            //turn off the pc speaker
  out $61,al
 end;
 end;
0
Comment
Question by:xbbin
7 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7101585
hello

  I think you can't do that with win2000/xp, cuz it's not allowed you to direct access the hardware

the code which using assemply with ports, doesn't work in any version based on NT, i'm not sure with that also with the PC speaker, but i think it's the same cuz u r using assembly code to access the hardware
0
 

Author Comment

by:xbbin
ID: 7101682
Hi,
I just want to turn on/off the pc speaker, How to do that without assembly code?
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 7101693
Try this:

// Disable Enable:
procedure TForm1.Button1Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETBEEP,0,NIL,SPIF_SENDWININICHANGE);
end;


// Enable Beep:
procedure TForm1.Button2Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETBEEP,1,NIL,SPIF_SENDWININICHANGE);
end;
 
tas
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:xbbin
ID: 7101706
Hi Tasomia,
Not have any sound at all.
0
 
LVL 2

Accepted Solution

by:
freshman3k earned 200 total points
ID: 7101927
Hello!

1)Download the following component:
http://www.torry.net/vcl/system/portaccess/smport.zip

2)Install the component

3)Place the component on the form

4)Put the following code in the formshow event:
SmallPort->OpenDriver;

5)Put the following code in the formclose event:
SmallPort->CloseDriver;

6)Use the following code to turn the pc speaker off:
SmallPort->SpeakerOff;

7)Use the following code to enable the pc and beep the speaker with a specified tone:
SmallPort->SpeakerOn(Tone);

8)Use the following code to enable the pc and beep the speaker with a specified Freq and delay:
SmallPort->Sound(Freq,Delay);

And This will work in all versions of windows.

>Please don't just tell me a component, I need the source

There is no way to accomplish that you want in winnt/win2k/winxp with just using assembly and not using drivers.

This component is free and includes sources for the drivers and the component.  

Good Luck! :-)
0
 

Author Comment

by:xbbin
ID: 7114073
Hi freshman,
Why can't install it on Delphi3? The compiler say: SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START and SERVICE_ERROR_NORMAL are undeclared identifier.

(Should I need to declared some unit on the "use" section??)

Delphi4 not have this problem.

Regards, bin
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 7114901
Hello bin,

Try Putting 'WinSvc.pas' unit in the implementation's uses
 

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question