Solved

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

Posted on 2002-06-23
7
343 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

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

Accepted Solution

by:
freshman3k earned 50 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 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