public void DoTests() { MMIOINFO mminfo = new MMIOINFO(); MMIOINFO mminfo2 = new MMIOINFO(); IntPtr ipOutput; ipOutput = MMIO.Open(sFilename, mminfo, MMIOFlags.ReadWrite); int i = MMIO.Seek(ipOutput, 0, MMIOSeekFlags.Set); Debug.Assert(i >= 0); MMIOError mm = MMIO.Flush(ipOutput, MMIOFlushFlags.None); MMIO.ThrowExceptionForError(mm); mm = MMIO.GetInfo(ipOutput, mminfo, Marshal.SizeOf(typeof(MMIOINFO))); MMIO.ThrowExceptionForError(mm); Debug.Assert(mminfo.dwFlags == MMIOFlags.ReadWrite); mm = MMIO.SetInfo(ipOutput, mminfo, Marshal.SizeOf(typeof(MMIOINFO))); MMIO.ThrowExceptionForError(mm); IntPtr ipbuff = Marshal.AllocCoTaskMem(BUFSIZE); mm = MMIO.SetBuffer(ipOutput, ipbuff, BUFSIZE, 0); MMIO.ThrowExceptionForError(mm); mm = MMIO.GetInfo(ipOutput, mminfo2, Marshal.SizeOf(typeof(MMIOINFO))); MMIO.ThrowExceptionForError(mm); mm = MMIO.Advance(ipOutput, mminfo2, RWMode.Read); MMIO.ThrowExceptionForError(mm); Debug.Assert(mminfo2.lDiskOffset == BUFSIZE); mm = MMIO.Close(ipOutput, MMIOCloseFlags.None); MMIO.ThrowExceptionForError(mm); mm = MMIO.Rename(sFilename, sFilename2, null, 0); MMIO.ThrowExceptionForError(mm); mm = MMIO.Rename(sFilename2, sFilename, null, 0); MMIO.ThrowExceptionForError(mm); }
/// <summary> /// Close the file /// </summary> public void Close() { if (!m_Disposed) { m_Closing = true; if (m_hDevice != IntPtr.Zero) { waveIn.Reset(m_hDevice); // Does an implicit Stop m_ProcReady.WaitOne(); // Wait for the thread to exit } // No point in hanging on to the buffers. The next file // we open may use different attributes. if (m_Buffers != null) { for (int x = 0; x < RECORDINGBUFFERS; x++) { m_Buffers[x].Release(m_hDevice); } m_Buffers = null; } if (m_hDevice != IntPtr.Zero) { waveIn.Close(m_hDevice); m_hDevice = IntPtr.Zero; } if (m_OutputFile != IntPtr.Zero) { WriteHeader(); MMIO.Flush(m_OutputFile, MMIOFlushFlags.None); MMIO.Close(m_OutputFile, MMIOCloseFlags.None); m_OutputFile = IntPtr.Zero; } m_AudioLength = 0; } else { throw new Exception("Instance is Disposed"); } }