33 Votes

Delphi: Difference between PlaySound and SNDPlaySound

Question by Guest | Last update on 2021-04-06 | Created on 2012-08-23

I wonder what the difference is between the two Delphi functions PlaySound and SNDPlaySound.

To me, it seems as if the two functions do the same and there is no difference. Or is there one?

ReplyPositiveNegative
Avatar
3Best Answer7 Votes

SNDPlaySound is an old function, PlaySound is the new extended function.

For compatibility reasons, the old version is still supported. So, to be prepared for the future, you should rather directly use PlaySound, because maybe at some point the support of SNDPlaySound can be given up.

Another difference arises from an additional parameter in PlaySound:

// both play the file test.wav
PlaySound('C:\test.wav', 0, SND_FILENAME OR SND_ASYNC);
SNDPlaySound('C:\test.wav', SND_FILENAME OR SND_ASYNC);
 
// play wave from a resource
PlaySound('RES', handle, SND_RESOURCE or SND_ASYNC);

With PlaySound, there is an additional option to indicate a handle to a resource (in the example "handle"). This makes it possible to play sounds directly from a resource. The top two lines of the code, both play the file "test.wav", once with PlaySound and once with SNDPlaySound.
Last update on 2021-04-06 | Created on 2012-08-25

ReplyPositive Negative
Reply

Related Topics

Delphi: Play System-Sounds

Tutorial | 0 Comments

Delphi: Hide Files

Question | 2 Answers

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.