public override void Release() { Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdsb8); Marshal.Release(this.pds8); //Marshal.ReleaseComObject(this.dsb8); //Marshal.ReleaseComObject(this.ds8); Marshal.FinalReleaseComObject(this.dsb8); Marshal.FinalReleaseComObject(this.ds8); this.pwfx_free = IntPtr.Zero; this.pdsb8 = IntPtr.Zero; this.pds8 = IntPtr.Zero; this.dsb8 = null; this.ds8 = null; foreach (var item in notifyHwnd_close) { Win32API.CloseHandle(item); } this.notifyHwnd_close = null; this.rgdsbpn = null; base.Release(); }
public int Release() { Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdsb8); Marshal.Release(this.pds8); //Marshal.ReleaseComObject(this.dsb8); //Marshal.ReleaseComObject(this.ds8); Marshal.FinalReleaseComObject(this.dsb8); Marshal.FinalReleaseComObject(this.ds8); this.pwfx_free = IntPtr.Zero; this.pdsb8 = IntPtr.Zero; this.pds8 = IntPtr.Zero; this.dsb8 = null; this.ds8 = null; foreach (var item in notifyHwnd_close) { DSLibNatives.CloseHandle(item); } this.notifyHwnd_close = null; return((int)DSERR.DS_OK); }
public int Release() { if (!this.isInit) { return(LibErrors.SUCCESS); } this.isInit = false; Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdsb8); Marshal.Release(this.pds8); //Marshal.ReleaseComObject(this.dsb8); //Marshal.ReleaseComObject(this.ds8); Marshal.FinalReleaseComObject(this.dsb8); Marshal.FinalReleaseComObject(this.ds8); this.pwfx_free = IntPtr.Zero; this.pdsb8 = IntPtr.Zero; this.pds8 = IntPtr.Zero; this.dsb8 = null; this.ds8 = null; foreach (var item in notifyHwnd_close) { LibNatives.CloseHandle(item); } this.notifyHwnd_close = null; this.rgdsbpn = null; return(LibErrors.SUCCESS); }
public override bool Close() { int dsErr = this.dsb8.Stop(); if (dsErr != DSERR.DS_OK) { logger.ErrorFormat("Stop失败, DSERR = {0}", dsErr); } Marshal.FreeHGlobal(this.pwfx_free); Marshal.Release(this.pdsb8); Marshal.Release(this.pds8); //Marshal.ReleaseComObject(this.dsb8); //Marshal.ReleaseComObject(this.ds8); Marshal.FinalReleaseComObject(this.dsb8); Marshal.FinalReleaseComObject(this.ds8); this.pwfx_free = IntPtr.Zero; this.pdsb8 = IntPtr.Zero; this.pds8 = IntPtr.Zero; this.dsb8 = null; this.ds8 = null; return(true); }
private bool CreateIDirectSound8() { uint error = Win32API.DirectSoundCreate8(IntPtr.Zero, out this.pds8, IntPtr.Zero); if (error != DSERR.DS_OK) { logger.ErrorFormat("DirectSoundCreate8失败, DSERR = {0}", error); return(false); } this.ds8 = Marshal.GetObjectForIUnknown(this.pds8) as IDirectSound8; if ((error = this.ds8.SetCooperativeLevel(Win32API.GetDesktopWindow(), DSSCL.DSSCL_NORMAL)) != DSERR.DS_OK) { logger.ErrorFormat("SetCooperativeLevel失败, DSERR = {0}", error); return(false); } return(true); }
//public int Pause() //{ // return DSERR.DS_OK; //} //public int Restore() //{ // return DSERR.DS_OK; //} #endregion #region 实例方法 private bool CreateIDirectSound8(IntPtr hwnd, out uint dsErr) { dsErr = DSLibNatives.DirectSoundCreate8(IntPtr.Zero, out this.pds8, IntPtr.Zero); if (dsErr != DSERR.DS_OK) { DSLibUtils.PrintLog("DirectSoundCreate8失败, DSERR = {0}", dsErr); return(false); } this.ds8 = Marshal.GetObjectForIUnknown(this.pds8) as IDirectSound8; dsErr = this.ds8.SetCooperativeLevel(hwnd, (int)DSSCL.DSSCL_NORMAL); if (dsErr != DSERR.DS_OK) { DSLibUtils.PrintLog("SetCooperativeLevel失败, DSERR = {0}", dsErr); return(false); } return(true); }
DirectSoundCreate8(Guid *lpcGuidDevice, out IDirectSound8 ppDS8, IntPtr pUnkOuter);
public static extern void DirectSoundCreate8(Guid *lpcGuidDevice, out IDirectSound8 ppDS8, IntPtr pUnkOuter);
public static extern void DirectSoundCreate8(Guid* lpcGuidDevice, out IDirectSound8 ppDS8, IntPtr pUnkOuter);
public override bool Open(WaveFormat af) { this.windowHandle = GetDesktopWindow(); this.audioFormat = af; #region 创建DirectSound对象 int dsErr = DirectSoundHelper.DirectSoundCreate8(IntPtr.Zero, out this.pds8, IntPtr.Zero); if (dsErr != DSERR.DS_OK) { logger.ErrorFormat("DirectSoundCreate8失败, DSERR = {0}", dsErr); return(false); } this.ds8 = Marshal.GetObjectForIUnknown(this.pds8) as IDirectSound8; dsErr = this.ds8.SetCooperativeLevel(this.windowHandle, DSSCL.DSSCL_NORMAL); if (dsErr != DSERR.DS_OK) { logger.ErrorFormat("SetCooperativeLevel失败, DSERR = {0}", dsErr); return(false); } #endregion #region 创建音频缓冲区对象 this.wfx = new WAVEFORMATEX() { nChannels = (short)this.audioFormat.Channel, nSamplesPerSec = this.audioFormat.SamplesPerSec, wBitsPerSample = (short)this.audioFormat.BitsPerSample, nBlockAlign = (short)this.audioFormat.BlockAlign, nAvgBytesPerSec = this.audioFormat.AvgBytesPerSec, cbSize = 0, wFormatTag = DirectSoundHelper.WAVE_FORMAT_PCM }; this.pwfx_free = Utils.StructureToPtr(this.wfx); this.dsbd = new DSBUFFERDESC() { dwSize = Marshal.SizeOf(typeof(DSBUFFERDESC)), dwFlags = DSBCAPS.DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS.DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS.DSBCAPS_GLOBALFOCUS | DSBCAPS.DSBCAPS_CTRLVOLUME, lpwfxFormat = this.pwfx_free, guid3DAlgorithm = new GUID(), dwBufferBytes = audioFormat.AvgBytesPerSec, dwReserved = 0 }; this.buffer_size = audioFormat.AvgBytesPerSec; this.min_free_space = this.wfx.nBlockAlign; IntPtr pdsb; dsErr = this.ds8.CreateSoundBuffer(ref this.dsbd, out pdsb, IntPtr.Zero); if (dsErr != DSERR.DS_OK) { logger.ErrorFormat("CreateSoundBuffer失败, DSERR = {0}", dsErr); return(false); } Guid iid_dsb8 = new Guid(IID.IID_IDirectSoundBuffer8); Marshal.QueryInterface(pdsb, ref iid_dsb8, out this.pdsb8); Marshal.Release(pdsb); this.dsb8 = Marshal.GetObjectForIUnknown(this.pdsb8) as IDirectSoundBuffer8; #endregion return(true); }