解决方案 »

  1.   

    你可以去www.pinvoke.net去查询相关的api函数。
      

  2.   

    [email protected] 我也要一份
      

  3.   

    [DllImport("winmm.dll")]
    static extern Int32 mciGetErrorString(Int32 errorCode,
       StringBuilder errorText, Int32 errorTextSize);[DllImport("winmm.dll")]
    static extern Int32 mciSendString(String command,
       StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);[DllImport("winmm.dll")]
    extern static Int32 midiStreamClose(IntPtr hMidiStream);[DllImport("winmm.dll")]
    extern static Int32 midiStreamOpen(ref IntPtr hMidiStream, ref Int32 puDeviceID, Int32 cMidi, IntPtr dwCallback, IntPtr dwInstance, Int32 fdwOpen);[DllImport("winmm.dll")]
    static extern TODO midiStreamOut(TODO);[DllImport("winmm.dll")]
    static extern Int32 midiStreamPause(IntPtr hMidiStream);[DllImport("winmm.dll")]
    static extern TODO midiStreamPosition(TODO);[DllImport("winmm.dll")]
    static extern TODO midiStreamProperty(TODO);[DllImport("winmm.dll")]
    static extern Int32 midiStreamRestart(IntPtr hMidiStream);[DllImport("winmm.dll")]
    static extern Int32 midiStreamStop(IntPtr hMidiStream);[DllImport("winmm.dll")]
    static extern Int32 mixerClose(IntPtr hmx);[DllImport("winmm.dll")]
    static extern Int32 mixerGetControlDetails(IntPtr hmxobj,
       ref MixerControlDetails pmxcd, UInt32 fdwDetailsmixer);[DllImport("winmm.dll")]
    static extern Int32 mixerGetLineControls(IntPtr hmxobj,
       ref MIXERLINECONTROLS pmxlc, UInt32 fdwControls);[DllImport("winmm.dll")]
    static extern Int32 mixerGetLineInfo(IntPtr hmxobj,
       ref MIXERLINE pmxl, UInt32 fdwInfo);[DllImport("winmm.dll", SetLastError=true)]
    static extern uint mixerGetNumDevs();[DllImport("winmm.dll")]
    static extern Int32 mixerOpen(ref IntPtr phmx, uint pMxId,
       IntPtr dwCallback, IntPtr dwInstance, UInt32 fdwOpen);[DllImport("winmm.dll")]
    static extern Int32 mixerSetControlDetails(IntPtr hmxobj,
       ref MixerControlDetails pmxcd, UInt32 fdwDetails);[DllImport("winmm.dll", SetLastError=true)]
    static extern bool PlaySound(string pszSound,
       System.UIntPtr hmod, uint fdwSound);/// <summary>
    /// Play Sound in bytes
    /// </summary>
    /// <param name="pszSound">Wave File Data</param>
    /// <param name="hmod"></param>
    /// <param name="dwFlag">Play Flag</param>
    /// <returns>succeed return true</returns>
    [DllImport("winmm.dll", SetLastError=true)]
    public static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlags dwFlag);///If you want to test with Button_Click() ,below code is show
    [System.Runtime.InteropServices.DllImport("winmm.dll", SetLastError=true)]
    static extern bool PlaySound(string pszSound,System.UIntPtr hmod, uint fdwSound);private void button2_Click(object sender, System.EventArgs e)
    {
      UIntPtr ip = UIntPtr.Zero;
      bool result = 
        PlaySound(
         @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music\New Stories (Highway Blues).wma"
         ,ip
         ,0);
    }[Flags]
        public enum SoundFlags : int
        {
            SND_SYNC = 0x0000,            // play synchronously (default)
            SND_ASYNC = 0x0001,        // play asynchronously
            SND_NODEFAULT = 0x0002,        // silence (!default) if sound not found
            SND_MEMORY = 0x0004,        // pszSound points to a memory file
            SND_LOOP = 0x0008,            // loop the sound until next sndPlaySound
            SND_NOSTOP = 0x0010,        // don't stop any currently playing sound
                /// <summary>
                /// Stop Playing Wave
                /// </summary>
                SND_PURGE = 0x40,
            SND_NOWAIT = 0x00002000,        // don't wait if the driver is busy
            SND_ALIAS = 0x00010000,        // name is a registry alias
            SND_ALIAS_ID = 0x00110000,        // alias is a predefined id
            SND_FILENAME = 0x00020000,        // name is file name
            SND_RESOURCE = 0x00040004        // name is resource name or atom
        }
        public static void Play (string strFileName)
        {
            PlaySound (strFileName, UIntPtr.Zero, (uint)(SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC));
        }    public static void Play (byte[] waveData)
        {
            PlaySound (waveData, IntPtr.Zero, PlayFlags.SND_ASYNC | PlayFlags.SND_MEMORY);
        }[DllImport("winmm.dll", EntryPoint="timeBeginPeriod")]
    public static extern uint MM_BeginPeriod(uint uMilliseconds);static void Main(string[] args)
    {
      StreamWriter oWriter = null;
      MM_BeginPeriod(1); // set timer resolution to 1ms => freq=1000Hz  try
      {
        oWriter = new StreamWriter(@"ticks.txt");
        // tickcount has resolution of 16.5ms, mmtime has 1ms
        for(int nLoop = 0; nLoop < 100000; nLoop++)
          oWriter.WriteLine("{0}: TickCount={1}, MMTime={2}", nLoop, Environment.TickCount, MM_GetTime());
      }
      catch(IOException oException)
      {
        Console.WriteLine(oException.Message);
      }
      finally
      {
        if(oWriter != null)
          oWriter.Close();
      }  MM_EndPeriod(1);
    }[DllImport("winmm.dll", EntryPoint="timeEndPeriod")]
    public static extern uint MM_EndPeriod(uint uMilliseconds);[DllImport("winmm.dll", SetLastError=true)]
    static extern UInt32 timeGetDevCaps( ref TimeCaps timeCaps,
                UInt32 sizeTimeCaps );[DllImport("winmm.dll", SetLastError=true)]
    static extern UInt32 timeGetSystemTime( ref MmTime mmTime, UInt32 sizeMmTime );[DllImport("winmm.dll", EntryPoint="timeGetTime")]
    public static extern uint MM_GetTime();[DllImport("winmm.dll", SetLastError=true)]
    static extern UInt32 timeKillEvent( UInt32 timerEventId );[DllImport("winmm.dll", SetLastError=true)]
    static extern UInt32 timeSetEvent( UInt32 msDelay, UInt32 msResolution,
                TimerEventHandler handler, ref UInt32 userCtx, UInt32 eventType );[DllImport("winmm.dll", SetLastError=true)]
    static extern TODO waveInGetNumDevs(TODO);[DllImport("winmm.dll", SetLastError=true)]
    static extern uint waveOutGetNumDevs();[DllImport("winmm.dll", SetLastError=true, CallingConvention=CallingConvention.Winapi)]
    public static extern int waveOutSetVolume(int uDeviceID, int dwVolume);