public static extern int waveInOpen( out IntPtr phwi, uint uDeviceID, ref Win32.WaveFormatEx pwfx, IntPtr dwCallback, IntPtr dwCallbackInstance, int fdwOpen);
public WaveOut(int deviceId, int samplesPerSec, int bitsPerSample, int channels) { Win32.WaveFormatEx pwfx = new Win32.WaveFormatEx(samplesPerSec, bitsPerSample, channels); this.eventHandler = new MessageThread(); IntPtr dwCallback = new IntPtr(this.eventHandler.Win32ThreadID); int num = Win32.waveOutOpen(out this.deviceHandle, (uint)deviceId, ref pwfx, dwCallback, IntPtr.Zero, 131072); if ((uint)num > 0U) { this.eventHandler.Dispose(); throw new Exception(string.Format("The device could not be opened ({0})", num)); } this.eventHandler.MessageHandlers[957] = m => { WaveBuffer waveBuffer = WaveBuffer.FromWaveHeader(Win32.WaveHeader.FromIntPtr(m.LParam)); Win32.waveOutUnprepareHeader(this.deviceHandle, waveBuffer.pHeader, Win32.WaveHeader.SizeOfWaveHeader); Interlocked.Add(ref this.enqueuedBufferSize, -waveBuffer.Data.Length); waveBuffer.Dispose(); if (this.OnDone == null) { return; } this.OnDone(); }; }