Ejemplo n.º 1
0
 private static void FreeHandle()
 {
     if (gcHandle != null)
     {
         Win32.PlaySound((byte[])null, UIntPtr.Zero, 0);
         gcHandle.Value.Free();
         gcHandle = null;
     }
 }
Ejemplo n.º 2
0
        public static void PlaySound(System.IO.Stream stream, SoundFlags flags)
        {
            LoadStream(stream);
            flags |= (SoundFlags.SND_MEMORY | SoundFlags.SND_ASYNC);

            if (BytesToPlay != null)
            {
                //  The byte array is pinned so that garbage collector cannot move it.
                gcHandle = System.Runtime.InteropServices.GCHandle.Alloc(BytesToPlay,
                                                                         System.Runtime.InteropServices.GCHandleType.Pinned);
                Win32.PlaySound(gcHandle.Value.AddrOfPinnedObject(), UIntPtr.Zero, (uint)flags);
            }
            else
            {
                Win32.PlaySound((byte[])null, UIntPtr.Zero, (uint)flags);
            }
        }