/// <summary> Retrieve the human-readable name of the filter </summary> protected string getName(System.Runtime.InteropServices.ComTypes.IMoniker moniker) { object bagObj = null; IPropertyBag bag = null; try { Guid bagId = typeof(IPropertyBag).GUID; moniker.BindToStorage(null, null, ref bagId, out bagObj); bag = (IPropertyBag)bagObj; object val = ""; int hr = bag.Read("FriendlyName", out val, null); //int hr = bag.Read("FriendlyName", ref val, IntPtr.Zero); Marshal.ThrowExceptionForHR(hr); string ret = val as string; if ((ret == null) || (ret.Length < 1)) throw new NotImplementedException("Device FriendlyName"); return (ret); } catch (Exception) { return (""); } finally { bag = null; if (bagObj != null) Marshal.ReleaseComObject(bagObj); bagObj = null; } }
public int SelectedFilter(System.Runtime.InteropServices.ComTypes.IMoniker pMon) { if (_blockedFilters.Count > 0) { object objBag = null; Guid ipGuid = typeof(IPropertyBag).GUID;//new Guid("55272A00-42CB-11CE-8135-00AA004BB851"); object objClsid = null; object objFriendlyName = null; try { pMon.BindToStorage(null, null, ref ipGuid, out objBag); IPropertyBag bag = objBag as IPropertyBag; if (bag != null) { bag.Read("CLSID", out objClsid, null); bag.Read("FriendlyName", out objFriendlyName, null); if (_blockedFilters.Contains(objClsid.ToString()) || _blockedFilters.Contains(objFriendlyName.ToString())) { FileLogger.Log("Blocked Filter: {0} - {1}", objFriendlyName, objClsid); return -1; } } } finally { if (objBag != null) Marshal.ReleaseComObject(objBag); } } return 0; }