using System;
using System.Runtime.InteropServices;
using System.Security;

namespace Apewer.Internals.Interop
{

    [SecuritySafeCritical]
    internal class WinMM
    {

        #region WinMM

        internal const int MMIO_FINDRIFF = 32;

        internal const int WAVE_FORMAT_PCM = 1;

        internal const int WAVE_FORMAT_ADPCM = 2;

        internal const int WAVE_FORMAT_IEEE_FLOAT = 3;

        internal const int MMIO_READ = 0;

        internal const int MMIO_ALLOCBUF = 65536;

        internal const int SND_SYNC = 0;

        internal const int SND_ASYNC = 1;

        internal const int SND_NODEFAULT = 2;

        internal const int SND_MEMORY = 4;

        internal const int SND_LOOP = 8;

        internal const int SND_PURGE = 64;

        internal const int SND_FILENAME = 131072;

        internal const int SND_NOSTOP = 16;

        [DllImport("winmm.dll")]
        public static extern long mciGetCreatorTask(long wDeviceID);

        [DllImport("winmm.dll")]
        public static extern long mciGetDeviceID(string lpstrName);

        [DllImport("winmm.dll", SetLastError = true)]
        public static extern long mciSendString(string lpstrCommand, ref string lpstrReturnString, int uReturnLength, IntPtr hwndCallback);

        [DllImport("WinMm.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr mmioOpen(string fileName, IntPtr not_used, int flags);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        public static extern int mmioAscend(IntPtr hMIO, MMCKINFO lpck, int flags);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        public static extern int mmioDescend(IntPtr hMIO, [MarshalAs(UnmanagedType.LPStruct)] MMCKINFO lpck, [MarshalAs(UnmanagedType.LPStruct)] MMCKINFO lcpkParent, int flags);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        public static extern int mmioRead(IntPtr hMIO, [MarshalAs(UnmanagedType.LPArray)] byte[] wf, int cch);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        public static extern int mmioClose(IntPtr hMIO, int flags);

        [DllImport("winmm.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool PlaySound(byte[] soundName, IntPtr hmod, int soundFlags);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        public static extern bool PlaySound([MarshalAs(UnmanagedType.LPWStr)] string soundName, IntPtr hmod, int soundFlags);

        [DllImport("winmm.dll")]
        public static extern long sndPlaySound(string lpszSoundName, long uFlags);

        #endregion

    }

}