public static IBaseFilter AddFilterByDevicePath(IGraphBuilder graphBuilder, string devicePath, string name) { int hr = 0; IBaseFilter filter = null; #if USING_NET11 UCOMIBindCtx bindCtx = null; UCOMIMoniker moniker = null; #else IBindCtx bindCtx = null; IMoniker moniker = null; #endif int eaten; if (graphBuilder.IsNull()) { throw new ArgumentNullException("graphBuilder"); } try { hr = NativeMethods.CreateBindCtx(0, out bindCtx); Marshal.ThrowExceptionForHR(hr); hr = NativeMethods.MkParseDisplayName(bindCtx, devicePath, out eaten, out moniker); Marshal.ThrowExceptionForHR(hr); hr = (graphBuilder as IFilterGraph2).AddSourceFilterForMoniker(moniker, bindCtx, name, out filter); DsError.ThrowExceptionForHR(hr); } catch { // An error occur. Just returning null... } finally { if (bindCtx.NotNull()) { Marshal.ReleaseComObject(bindCtx); } if (moniker.NotNull()) { Marshal.ReleaseComObject(moniker); } } return(filter); }