Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than coredll, prefix the name with the module name and a period.
PlaySound (coredll)
coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for PlaySound in other DLLs exists, click on Find References to the right.
.
For playing files:
C# Signature:
[DllImport("winmm.dll", SetLastError = true)]
[DllImport("coredll.dll")]
public static extern int PlaySound(
string szSound,
IntPtr hModule,
int flags);
VB Signature:
<DllImport("winmm.dll", SetLastError = True)> _
<DllImport("coredll.dll")> _
Public Shared Function PlaySound( _
ByVal szSound As String, _
ByVal hModule As IntPtr, _
ByVal flags As Integer) As Integer
End Function
For playing streams/bytearrays:
C# Signature:
[DllImport("winmm.dll", SetLastError = true)]
[DllImport("coredll.dll")]
public static extern int PlaySound(
byte[] szSound,
IntPtr hModule,
int flags);
VB Signature:
<DllImport("winmm.dll", SetLastError = True)> _
<DllImport("coredll.dll")> _
Public Shared Function PlaySound( _
ByVal szSound() As Byte, _
ByVal hModule As IntPtr, _
ByVal flags As Integer) As Integer
End Function
Private Enum PlaySoundFlags As UInt32
SND_SYNC = &H0 ' play synchronously (default)
SND_ASYNC = &H1 ' play asynchronously
SND_NODEFAULT = &H2 ' silence (!default) if sound not found
SND_MEMORY = &H4 ' pszSound points to a memory file
SND_LOOP = &H8 ' loop the sound until next sndPlaySound
SND_NOSTOP = &H10 ' don't stop any currently playing sound
SND_NOWAIT = &H2000 ' don't wait if the driver is busy
SND_ALIAS = &H10000 ' name is a registry alias
SND_ALIAS_ID = &H110000 ' alias is a predefined ID
SND_FILENAME = &H20000 ' name is file name
SND_RESOURCE = &H40004 ' name is resource name or atom
End Enum
public enum PlaySoundFlags : uint {
SND_SYNC = 0x0, // play synchronously (default)
SND_ASYNC = 0x1, // play asynchronously
SND_NODEFAULT = 0x2, // silence (!default) if sound not found
SND_MEMORY = 0x4, // pszSound points to a memory file
SND_LOOP = 0x8, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x10, // don't stop any currently playing sound
SND_NOWAIT = 0x2000, // don't wait if the driver is busy
SND_ALIAS = 0x10000, // name is a registry alias
SND_ALIAS_ID = 0x110000, // alias is a predefined ID
SND_FILENAME = 0x20000, // name is file name
SND_RESOURCE = 0x40004, // name is resource name or atom
};
Notes:
Returns True (e.g. 1) for success and False (0) for error.
If the function returns True but there is no sound, check Settings / Sounds & Notifications / Enable sounds for / Programs / Notifications
on your PDA
Tips & Tricks:
Please add some!
C# Sample Code
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Sound
{
public enum PlaySoundFlags : int {
SND_SYNC = 0x0, // play synchronously (default)
SND_ASYNC = 0x1, // play asynchronously
SND_NODEFAULT = 0x2, // silence (!default) if sound not found
SND_MEMORY = 0x4, // pszSound points to a memory file
SND_LOOP = 0x8, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x10, // don't stop any currently playing sound
SND_NOWAIT = 0x2000, // don't wait if the driver is busy
SND_ALIAS = 0x10000, // name is a registry alias
SND_ALIAS_ID = 0x110000,// alias is a predefined ID
SND_FILENAME = 0x20000, // name is file name
SND_RESOURCE = 0x40004, // name is resource name or atom
};
public class Sound
{
[DllImport("winmm.dll", SetLastError = true)]
[DllImport("coredll.dll")]
public static extern int PlaySound(
string szSound,
IntPtr hModule,
int flags);
public static void Beep() {
Play(@"\Windows\Voicbeep");
}
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Runtime.InteropServices
Public Class Sounds
<Flags()> _
Private Enum PlaySoundFlags
SND_SYNC = &H0 ' play synchronously (default)
SND_ASYNC = &H1 ' play asynchronously
SND_NODEFAULT = &H2 ' silence (!default) if sound not found
SND_MEMORY = &H4 ' pszSound points to a memory file
SND_LOOP = &H8 ' loop the sound until next sndPlaySound
SND_NOSTOP = &H10 ' don't stop any currently playing sound
SND_NOWAIT = &H2000 ' don't wait if the driver is busy
SND_ALIAS = &H10000 ' name is a registry alias
SND_ALIAS_ID = &H110000 ' alias is a predefined ID
SND_FILENAME = &H20000 ' name is file name
SND_RESOURCE = &H40004 ' name is resource name or atom
End Enum
<DllImport("winmm.dll", SetLastError = True)> _
<DllImport("coredll.dll")> _
Public Shared Function PlaySound( _
ByVal szSound As String, _
ByVal hModule As IntPtr, _
ByVal flags As Integer) As Integer
End Function
Public Shared Sub Play(ByVal fileName As String)
Try
PlaySound(fileName, IntPtr.Zero, PlaySoundFlags.SND_FILENAME Or _
PlaySoundFlags.SND_SYNC)
Catch ex As Exception
MessageBox.Show("Can't play sound file. " & ex.ToString)
End Try
End Sub
End Class
Alternative Managed API:
None.
Plays a sound
1/12/2014 7:20:59 AM - -65.10.102.204
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
Plays a sound
1/12/2014 7:20:59 AM - -65.10.102.204
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).