public int Release() { Marshal.FreeHGlobal(this.pBufferDesc_free); Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdscb8); Marshal.Release(this.pdsc8); //Marshal.ReleaseComObject(this.dscb8); //Marshal.ReleaseComObject(this.dsc8); Marshal.FinalReleaseComObject(this.dscb8); Marshal.FinalReleaseComObject(this.dsc8); this.pBufferDesc_free = IntPtr.Zero; this.pwfx_free = IntPtr.Zero; this.pdscb8 = IntPtr.Zero; this.pdsc8 = IntPtr.Zero; this.dscb8 = null; this.dsc8 = null; foreach (var hwnd in this.notifyHwnd_close) { DSLibNatives.CloseHandle(hwnd); } this.notifyHwnd_close = null; return((int)DSERR.DS_OK); }
public override void Release() { Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdscb8); Marshal.Release(this.pdsc8); //Marshal.ReleaseComObject(this.dscb8); //Marshal.ReleaseComObject(this.dsc8); Marshal.FinalReleaseComObject(this.dscb8); Marshal.FinalReleaseComObject(this.dsc8); this.pwfx_free = IntPtr.Zero; this.pdscb8 = IntPtr.Zero; this.pdsc8 = IntPtr.Zero; this.dscb8 = null; this.dsc8 = null; foreach (var handle in this.notifyHandle_close) { Win32API.CloseHandle(handle); } this.notifyHandle_close = null; base.Release(); }
public int Release() { Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdscb8); Marshal.Release(this.pdsc8); //Marshal.ReleaseComObject(this.dscb8); //Marshal.ReleaseComObject(this.dsc8); Marshal.FinalReleaseComObject(this.dscb8); Marshal.FinalReleaseComObject(this.dsc8); this.pwfx_free = IntPtr.Zero; this.pdscb8 = IntPtr.Zero; this.pdsc8 = IntPtr.Zero; this.dscb8 = null; this.dsc8 = null; foreach (var hwnd in this.notifyHwnd_close) { LibNatives.CloseHandle(hwnd); } this.notifyHwnd_close = null; return(LibErrors.SUCCESS); }
private bool CreateCaptureBuffer(out uint dsErr) { dsErr = DSERR.DS_OK; #region 创建默认音频流格式 this.wfx = new tWAVEFORMATEX() { nChannels = DSLibConsts.Channels, nSamplesPerSec = DSLibConsts.SamplesPerSec, wBitsPerSample = DSLibConsts.BitsPerSample, nBlockAlign = DSLibConsts.BlockAlign, nAvgBytesPerSec = DSLibConsts.Bps, cbSize = 0, wFormatTag = DSLibNatives.WAVE_FORMAT_PCM }; this.pwfx_free = DSLibUtils.StructureToPtr(this.wfx); this.bufferDesc = new _DSCBUFFERDESC() { dwFlags = 0, dwSize = Marshal.SizeOf(typeof(_DSCBUFFERDESC)), dwReserved = 0, dwFXCount = 0, dwBufferBytes = DSLibConsts.BufferSize, lpwfxFormat = this.pwfx_free, lpDSCFXDesc = IntPtr.Zero }; this.pBufferDesc_free = DSLibUtils.StructureToPtr(this.bufferDesc); #endregion IntPtr pdscb; Guid iid_dscb8; dsErr = this.dsc8.CreateCaptureBuffer(this.pBufferDesc_free, out pdscb, IntPtr.Zero); //TestInvoke2(this.free_bufferDesc, out ppDSCBuff); if (dsErr == DSERR.DS_OK) { // 获取IDirectSoundCaptureBuffer8接口实例 iid_dscb8 = new Guid(IID.IID_IDirectSoundCaptureBuffer8); Marshal.QueryInterface(pdscb, ref iid_dscb8, out this.pdscb8); Marshal.Release(pdscb); this.dscb8 = Marshal.GetObjectForIUnknown(this.pdscb8) as IDirectSoundCaptureBuffer8; } else { DSLibUtils.PrintLog("CreateCaptureBuffer失败, DSERROR = {0}", dsErr); return(false); } return(true); }
private bool CreateCaptureBuffer() { uint error = DSERR.DS_OK; #region 创建默认音频流格式 this.wfx = new WAVEFORMATEX() { nChannels = Channel, nSamplesPerSec = SamplesPerSec, wBitsPerSample = BitsPerSample, nBlockAlign = BlockAlign, nAvgBytesPerSec = BytesPerSec, cbSize = 0, wFormatTag = Win32API.WAVE_FORMAT_PCM }; this.pwfx_free = PInvoke.StructureToPtr(this.wfx); this.dsbd = new DSCBUFFERDESC() { dwFlags = 0, dwSize = Marshal.SizeOf(typeof(DSCBUFFERDESC)), dwReserved = 0, dwFXCount = 0, dwBufferBytes = BufferSize, lpwfxFormat = this.pwfx_free, lpDSCFXDesc = IntPtr.Zero }; #endregion IntPtr pdscb; Guid iid_dscb8; if ((error = this.dsc8.CreateCaptureBuffer(ref this.dsbd, out pdscb, IntPtr.Zero)) == DSERR.DS_OK) { // 获取IDirectSoundCaptureBuffer8接口实例 iid_dscb8 = new Guid(InterfaceID.IID_IDirectSoundCaptureBuffer8); Marshal.QueryInterface(pdscb, ref iid_dscb8, out this.pdscb8); Marshal.Release(pdscb); this.dscb8 = Marshal.GetObjectForIUnknown(this.pdscb8) as IDirectSoundCaptureBuffer8; } else { logger.ErrorFormat("CreateCaptureBuffer失败, DSERROR = {0}", error); return(false); } return(true); }