Exemplo n.º 1
0
        /// <summary> Retrieve the human-readable name of the filter </summary>
        protected string getName(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", ref val, IntPtr.Zero);
                //if( hr != 0 )
                //	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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the Guid for a moniker
        /// </summary>
        /// <returns>String or null on error</returns>
        public static Guid GetMonikerGuid(IMoniker m_Mon)
        {
            IPropertyBag bag    = null;
            Guid         ret    = Guid.Empty;
            object       bagObj = null;
            object       val    = null;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                m_Mon.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag)bagObj;

                int hr = bag.Read("clsid", out val, null);
                DsError.ThrowExceptionForHR(hr);

                ret = new Guid(val as string);
            }
            catch
            {
                ret = Guid.Empty;
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the FriendlyName for a moniker
        /// </summary>
        /// <returns>String or null on error</returns>
        public static string GetFriendlyName(IMoniker m_Mon)
        {
            IPropertyBag bag    = null;
            string       ret    = null;
            object       bagObj = null;
            object       val    = null;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                m_Mon.BindToStorage(null, null, ref bagId, out bagObj);

                bag = (IPropertyBag)bagObj;

                int hr = bag.Read("FriendlyName", out val, null);
                DsError.ThrowExceptionForHR(hr);

                ret = val as string;
            }
            catch
            {
                ret = null;
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }

            return(ret);
        }
Exemplo n.º 4
0
        private string GetName(IMoniker moniker)
        {
            object       bagObject = null;
            IPropertyBag bag       = null;

            try
            {
                var bagId = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref bagId, out bagObject);
                bag = (IPropertyBag)bagObject;
                object value   = string.Empty;
                int    hresult = bag.Read("FriendlyName", ref value, IntPtr.Zero);
                if (hresult != 0)
                {
                    Marshal.ThrowExceptionForHR(hresult);
                }
                string returnValue = (string)value;
                if ((returnValue == null) || (returnValue.Length < 1))
                {
                    throw new ApplicationException();
                }
                return(returnValue);
            }
            catch (Exception) { return(string.Empty); }
            finally
            {
                bag = null;
                if (bagObject != null)
                {
                    Marshal.ReleaseComObject(bagObject); bagObject = null;
                }
            }
        }
Exemplo n.º 5
0
		/// <summary> Retrieve the human-readable name of the filter </summary>
		protected string getName(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", ref val, IntPtr.Zero );
				//if( hr != 0 )
				//	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;
			}
		}
Exemplo n.º 6
0
        /// <summary>
        /// Get friendly name of the device
        /// </summary>
        /// <param name="monikers"></param>
        /// <param name="displayName"></param>
        /// <returns></returns>
        private string GetFriendlyName(IMoniker moniker)
        {
            int    hr          = 0;
            string displayName = string.Empty;
            ///Get selected device name
            object       bagObj          = null;
            object       propValue       = null;
            IPropertyBag monikerProperty = null;

            Guid propertyBagGuid = typeof(IPropertyBag).GUID;

            moniker.BindToStorage(null, null, ref propertyBagGuid, out bagObj);
            monikerProperty = (IPropertyBag)bagObj;
            hr = monikerProperty.Read("FriendlyName", out propValue, null);

            displayName = propValue as string;
            if (hr != 0 || string.IsNullOrEmpty(displayName))
            {
                displayName = "Unknown";
            }

            if (bagObj != null)
            {
                Marshal.ReleaseComObject(bagObj);
            }

            return(displayName);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get a specific PropertyBag value from a moniker
        /// </summary>
        /// <param name="sPropName">The name of the value to retrieve</param>
        /// <returns>String or null on error</returns>
        public string GetPropBagValue(string sPropName)
        {
            IPropertyBag bag    = null;
            string       ret    = null;
            object       bagObj = null;
            object       val    = null;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                _moniker.BindToStorage(null, null, ref bagId, out bagObj);

                bag = (IPropertyBag)bagObj;

                int hr = bag.Read(sPropName, out val, null);
                DsError.ThrowExceptionForHR(hr);

                ret = val as string;
            }
            catch
            {
                ret = null;
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    DsUtils.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }

            return(ret);
        }
Exemplo n.º 8
0
        /// <summary> Retrieve the human-readable name of the filter </summary>
        private string GetName(IMoniker moniker)
        {
            try
            {
                var bagId = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref bagId, out var bagObj);
                using (var bag = new ComWrapper <IPropertyBag>((IPropertyBag)bagObj))
                {
                    var hr = bag.Object.Read("FriendlyName", out var val, null);
                    if (hr != 0)
                    {
                        return(string.Empty);
                    }

                    var ret = val as string;
                    hr = bag.Object.Read("CLSID", out val, null);
                    if (hr == 0)
                    {
                        _classId = new Lazy <Guid>(() => new Guid(val.ToString()));
                    }

                    return(ret ?? string.Empty);
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the moniker unique identifier.
        /// </summary>
        /// <param name="moniker">The moniker.</param>
        /// <returns>Returns moniker identifier</returns>
        public static Guid GetMonikerGuid(IMoniker moniker)
        {
            Guid   ret;
            object bagObj = null;

            try
            {
                var bagId = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref bagId, out bagObj);
                var bag = (IPropertyBag)bagObj;

                var hr = bag.Read("clsid", out var val, null);
                ret = hr >= 0 ? (val is string s ? new Guid(s) : Guid.Empty) : Guid.Empty;
            }
            catch
            {
                ret = Guid.Empty;
            }
            finally
            {
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                }
            }

            return(ret);
        }
Exemplo n.º 10
0
        private void DisplayDebugInformation(IMoniker moniker, Guid filterClsid)
        {
            IPropertyBag propertyBag = null;

            try
            {
                string registryPath   = string.Format(@"HKEY_CLASSES_ROOT\CLSID\{0}\InprocServer32", filterClsid.ToString("B"));
                string filterLocation = (string)Registry.GetValue(registryPath, string.Empty, string.Empty);

                object o;
                Guid   IID_IPropertyBag = typeof(IPropertyBag).GUID;

                moniker.BindToStorage(null, null, ref IID_IPropertyBag, out o);
                propertyBag = (IPropertyBag)o;

                int hr = propertyBag.Read("FriendlyName", out o, null);
                Marshal.ThrowExceptionForHR(hr);

                string friendlyName = o.ToString();

                Debug.WriteLine(string.Format("Localtion: {0}\r\nFriendly Name: {1}", filterLocation, friendlyName));
            }
            catch { }
            finally
            {
                if (propertyBag != null)
                {
                    Marshal.ReleaseComObject(propertyBag);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Liest eine bestimmte Eigenschaft eines eindeutigen Namens.
        /// </summary>
        /// <param name="moniker">Der eindeutige Name.</param>
        /// <param name="property">Name der gewünschten Eigenschaft.</param>
        /// <returns>Wert der Eigenschaft.</returns>
        public static string ReadProperty(this IMoniker moniker, string property)
        {
            // Validate
            if (moniker == null)
            {
                return(null);
            }

            // Guid for reference
            Guid propBag = new Guid("55272a00-42cb-11ce-8135-00aa004bb851");

            // Prepare for errors
            try
            {
                // Change interface
                var props = moniker.BindToStorage(null, null, ref propBag);
                try
                {
                    // Report
                    return(((IPropertyBag)props).Get <string>(property));
                }
                finally
                {
                    // Cleanup
                    BDAEnvironment.Release(ref props);
                }
            }
            catch
            {
                // Do nothing in case of ANY error
                return(null);
            }
        }
Exemplo n.º 12
0
    private static bool GetFriendlyName(IMoniker mon, ref string devname, ref string devpath)
    {
        object       bagObj = null;
        IPropertyBag bag    = null;

        try
        {
            Guid bagId = typeof(IPropertyBag).GUID;
            mon.BindToStorage(null, null, ref bagId, out bagObj);
            bag = (IPropertyBag)bagObj;
            object val = "";
            int    hr  = bag.Read("Description", ref val, IntPtr.Zero);
            if (hr != 0)
            {
                hr = bag.Read("FriendlyName", ref val, IntPtr.Zero);
            }
            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            devname = val as string;
            if ((devname == null) || (devname.Length < 1))
            {
                throw new NotImplementedException("Device FriendlyName");
            }
            val = "";
            hr  = bag.Read("DevicePath", ref val, IntPtr.Zero);
            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            devpath = val as string;
            if ((devpath == null) || (devpath.Length < 1))
            {
                throw new NotImplementedException("Device Path");
            }
            return(true);
        }
        catch (Exception)
        {
            return(false);
        }
        finally
        {
            bag = null;
            if (bagObj != null)
            {
                Marshal.ReleaseComObject(bagObj);
            }
            bagObj = null;
        }
    }
Exemplo n.º 13
0
        bool TryGetPropertyBag(IMoniker moniker, out IPropertyBag propertyBag)
        {
            var iidPropertyBag = typeof(IPropertyBag).GUID;

            moniker.BindToStorage(null, null, ref iidPropertyBag, out var storage);
            propertyBag = storage as IPropertyBag;
            if (propertyBag == null)
            {
                Marshal.ReleaseComObject(storage);
                propertyBag = null;
                return(false);
            }
            return(true);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the name of a specific moniker
        /// </summary>
        /// <param name="moniker">Moniker object to get the name of</param>
        /// <returns>Name of a specific moniker</returns>
        private static string GetName(IMoniker moniker)
        {
            // Declare variables
            Object       bagObj = null;
            IPropertyBag bag    = null;

            try
            {
                // Bind the moniker to storage
                Guid bagId = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag)bagObj;

                // Try to retrieve the friendly name
                object val = "";
                int    hr  = bag.Read("FriendlyName", ref val, IntPtr.Zero);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Convert to string & validate
                string result = (string)val;
                if (string.IsNullOrEmpty(result))
                {
                    throw new ApplicationException();
                }

                // Return result
                return(result);
            }
            catch (Exception)
            {
                // Return empty string
                return(string.Empty);
            }
            finally
            {
                // Clean up
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 15
0
        /// <summary> Retrieve the human-readable name of the filter </summary>
        protected string getName(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);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                string ret = val as string;
                if ((ret == null) || (ret.Length < 1))
                {
                    throw new NotImplementedException("Device FriendlyName");
                }

                hr = bag.Read("CLSID", out val, null);
                if (hr == 0)
                {
                    CLSID = new Guid(val.ToString());
                }

                return(ret);
            }
            catch (Exception)
            {
                return("");
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    DirectShowUtil.ReleaseComObject(bagObj);
                }
                bagObj = null;

                _nameResolved = true;
            }
        }
Exemplo n.º 16
0
        //
        // Get filter name represented by the moniker
        //
        private string GetName(IMoniker moniker)
        {
            Object       bagObj = null;
            IPropertyBag bag    = null;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                // get property bag of the moniker
                moniker.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag)bagObj;

                // read FriendlyName
                object val = "";
                int    hr  = bag.Read("FriendlyName", ref val, IntPtr.Zero);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // get it as string
                string ret = (string)val;
                if ((ret == null) || (ret.Length < 1))
                {
                    throw new ApplicationException( );
                }

                return(ret);
            }
            catch (Exception ex)
            {
                AForgeLogger.Instance.LogError(ex.Message);
                return("");
            }
            finally
            {
                // release all COM objects
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 17
0
        private void BindMonikerToStream(IMoniker pmk, IBindCtx pbc)
        {
            Guid   iid     = Guids.IID_IStream;
            object pStream = null;

            try
            {
                pmk.BindToStorage(pbc, null, ref iid, out pStream);
            }
            catch (COMException)
            {
                //s_log.InfoFormat ("COM Exception occured in DownloadManagerImplementation.BindMonikerToStream: Message: {}", ex.Message);
            }
            if (pStream != null)
            {
                Marshal.ReleaseComObject(pStream);                 // don't need the stream, we get asynchronous callbacks
            }
        }
Exemplo n.º 18
0
        //
        // Get filter name represented by the moniker
        //
        private string GetName(IMoniker moniker)
        {
            Object       bagObj = null;
            IPropertyBag bag;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                // get property bag of the moniker
                moniker.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag)bagObj;

                // read FriendlyName
                object val = "";
                int    hr  = bag.Read("FriendlyName", ref val, IntPtr.Zero);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // get it as string
                var ret = (string)val;
                if (string.IsNullOrEmpty(ret))
                {
                    throw new ApplicationException( );
                }

                return(ret);
            }
            catch (Exception)
            {
                return("");
            }
            finally
            {
                // release all COM objects
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 19
0
        private string GetName(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", ref val, IntPtr.Zero);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }


                string ret = (string)val;
                if ((ret == null) || (ret.Length < 1))
                {
                    throw new ApplicationException( );
                }

                return(ret);
            }
            catch (Exception)
            {
                return("");
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 20
0
        // Get filter name represented by the moniker
        private string GetName(IMoniker moniker)
        {
            Object			bagObj = null;
            IPropertyBag	bag = null;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                // get property bag of the moniker
                moniker.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag) bagObj;

                // read FriendlyName
                object val = "";
                int hr = bag.Read("FriendlyName", ref val, IntPtr.Zero);
                if (hr != 0)
                    Marshal.ThrowExceptionForHR(hr);

                // get it as string
                string ret = val as string;
                if ((ret == null) || (ret.Length < 1))
                    throw new ApplicationException();

                return ret;
            }
            catch (Exception)
            {
                return "";
            }
            finally
            {
                // release all COM objects
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 21
0
        private string WriteList(IMoniker init)
        {
            //Discarded unreachable code: IL_0002
            //IL_0003: Incompatible stack heights: 0 vs 1
            object        ppvObj        = null;
            ConsumerEvent consumerEvent = null;

            try
            {
                Guid riid = typeof(ConsumerEvent).GUID;
                init.BindToStorage(null, null, ref riid, out ppvObj);
                consumerEvent = (ConsumerEvent)ppvObj;
                object token = "";
                int    num   = consumerEvent._0001("FriendlyName", ref token, IntPtr.Zero);
                if (num != 0)
                {
                    Marshal.ThrowExceptionForHR(num);
                }
                string text = (string)token;
                if (text == null || text.Length < 1)
                {
                    throw new ApplicationException();
                }
                return(text);
            }
            catch (Exception)
            {
                return("");
            }
            finally
            {
                consumerEvent = null;
                if (ppvObj != null)
                {
                    Marshal.ReleaseComObject(ppvObj);
                    ppvObj = null;
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Retrieve the human-readable name of the filter
        /// </summary>
        protected string GetName(IMoniker moniker)
        {
            object bagObj = null;

            try
            {
                var bagId = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref bagId, out bagObj);

                var bag = (IPropertyBag)bagObj;
                var hr  = bag.Read("FriendlyName", out var val, null);

                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                var ret = val as string;

                if (string.IsNullOrEmpty(ret))
                {
                    throw new NotImplementedException("Device FriendlyName");
                }

                return(ret);
            }
            catch (Exception)
            {
                return("");
            }
            finally
            {
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                }
                bagObj = null;
            }
        }
Exemplo n.º 23
0
            public VideoCaptureDevice(IMoniker moniker)
            {
                Debug.Assert(moniker != null);
                this.moniker = moniker;

                // retrieve name
                Guid   bagRiid       = typeof(IPropertyBag).GUID;
                object propertyValue = null;
                object bag           = null;

                try {
                    moniker.BindToStorage(null, null, ref bagRiid, out bag);
                    ((IPropertyBag)bag).Read("FriendlyName", out propertyValue, null);
                } catch {
                } finally {
                    if (bag != null)
                    {
                        Marshal.ReleaseComObject(bag);
                    }
                }
                name = propertyValue as string;
            }
Exemplo n.º 24
0
        private string GetName(IMoniker moniker)
        {
            object       ppvObj      = null;
            IPropertyBag propertyBag = null;

            try
            {
                Guid riid = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref riid, out ppvObj);
                propertyBag = (IPropertyBag)ppvObj;
                object pVar = "";
                int    num  = propertyBag.Read("FriendlyName", ref pVar, IntPtr.Zero);
                if (num != 0)
                {
                    Marshal.ThrowExceptionForHR(num);
                }
                string text = (string)pVar;
                if (text == null || text.Length < 1)
                {
                    throw new ApplicationException();
                }
                return(text);
            }
            catch (Exception)
            {
                return("");
            }
            finally
            {
                propertyBag = null;
                if (ppvObj != null)
                {
                    Marshal.ReleaseComObject(ppvObj);
                    ppvObj = null;
                }
            }
        }
        // Token: 0x06000020 RID: 32 RVA: 0x0000231C File Offset: 0x0000051C
        private string GetName(IMoniker moniker)
        {
            object obj = null;
            string result;

            try
            {
                Guid guid = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref guid, out obj);
                IPropertyBag propertyBag = (IPropertyBag)obj;
                object       obj2        = "";
                int          num         = propertyBag.Read("FriendlyName", ref obj2, IntPtr.Zero);
                if (num != 0)
                {
                    Marshal.ThrowExceptionForHR(num);
                }
                string text = (string)obj2;
                if (text == null || text.Length < 1)
                {
                    throw new ApplicationException();
                }
                result = text;
            }
            catch (Exception)
            {
                result = "";
            }
            finally
            {
                if (obj != null)
                {
                    Marshal.ReleaseComObject(obj);
                    obj = null;
                }
            }
            return(result);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Retrieves the property of the specified property name from
        /// the specified moniker
        /// </summary>
        /// <param name="moniker">moniker to retrieve from</param>
        /// <param name="propertyName">name of the property to retrieve</param>
        /// <returns>the property, null if invalid property</returns>
        private static string getPropBagValue(IMoniker moniker, string propertyName)
        {
            string retVal    = null;
            object bagObject = null;

            try
            {
                var guid = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref guid, out bagObject);

                var bag = (IPropertyBag)bagObject;

                object val;
                var    hResult = bag.Read(propertyName, out val, null);

                if (hResult != S_OK)
                {
                    return(retVal);
                }

                retVal = val as string;
            }
            catch
            {
                retVal = null;
            }
            finally
            {
                if (bagObject != null)
                {
                    Marshal.ReleaseComObject(bagObject);
                }
            }

            return(retVal);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets the name of a specific moniker
        /// </summary>
        /// <param name="moniker">Moniker object to get the name of</param>
        /// <returns>Name of a specific moniker</returns>
        private static string GetName(IMoniker moniker)
        {
            // Declare variables
            Object bagObj = null;
            IPropertyBag bag = null;

            try
            {
                // Bind the moniker to storage
                Guid bagId = typeof(IPropertyBag).GUID;
                moniker.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag)bagObj;

                // Try to retrieve the friendly name
                object val = "";
                int hr = bag.Read("FriendlyName", ref val, IntPtr.Zero);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Convert to string & validate
                string result = (string)val;
                if (string.IsNullOrEmpty(result))
                {
                    throw new ApplicationException();
                }

                // Return result
                return result;
            }
            catch (Exception)
            {
                // Return empty string
                return string.Empty;
            }
            finally
            {
                // Clean up
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 28
0
    /// <summary> Retrieve the human-readable name of the filter </summary>
    protected string getName(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);
        if (hr != 0)
        {
          Marshal.ThrowExceptionForHR(hr);
        }
        string ret = val as string;
        if ((ret == null) || (ret.Length < 1))
        {
          throw new NotImplementedException("Device FriendlyName");
        }

        hr = bag.Read("CLSID", out val, null);
        if (hr == 0)
        {
          CLSID = new Guid(val.ToString());
        }

        return (ret);
      }
      catch (Exception)
      {
        return ("");
      }
      finally
      {
        bag = null;
        if (bagObj != null)
        {
          DirectShowUtil.ReleaseComObject(bagObj);
        }
        bagObj = null;

        _nameResolved = true;
      }
    }
Exemplo n.º 29
0
        private string GetName(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 = null;
                int hr = bag.Read("FriendlyName", ref val, IntPtr.Zero);
                if (hr != 0)
                    Marshal.ThrowExceptionForHR(hr);
                return (string)val;
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Constructor from an IMoniker
        /// </summary>
        /// <param name="m_Mon"></param>
        public FilterData(IMoniker m_Mon)
        {
            IPropertyBag bag = null;

            byte[] filterData = null;
            object bagObj     = null;
            object val        = null;

            try
            {
                Guid bagId = typeof(IPropertyBag).GUID;
                m_Mon.BindToStorage(null, null, ref bagId, out bagObj);
                bag = (IPropertyBag)bagObj;

                bag.Read("FilterData", out val, null);
                filterData = (byte[])val;
            }
            catch
            {
                filterData = null;
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                    bagObj = null;
                }
            }

            if (filterData != null)
            {
                // get the FilterData version and Merit
                Version = IntFromBytes(filterData, 0);
                Merit   = IntFromBytes(filterData, 4);

                // Parse the pins
                NumPins = IntFromBytes(filterData, 8);
                int iPos = 16;
                for (int z = 0; z < NumPins; z++)
                {
                    int  iMT     = IntFromBytes(filterData, iPos + 12);
                    int  iMedium = IntFromBytes(filterData, iPos + 16);
                    int  flag    = IntFromBytes(filterData, iPos + 4);
                    int  inst    = IntFromBytes(filterData, iPos + 8);
                    Guid cat     = GuidFromOffset(filterData, iPos + 20);

                    FilterDataPin fdp = new FilterDataPin(z, flag, inst, cat);
                    iPos += 24;

                    // Parse the media types for the pin
                    for (int x = 0; x < iMT; x++)
                    {
                        fdp.Types.Add(new FilterDataPinType(x, GuidFromOffset(filterData, iPos + 8), GuidFromOffset(filterData, iPos + 12)));
                        iPos += 16;
                    }

                    // Parse the mediums for the pin
                    for (int y = 0; y < iMedium; y++)
                    {
                        fdp.Mediums.Add(new FilterDataPinType(y, GuidFromOffset(filterData, iPos), Guid.Empty));
                        iPos += 4;
                    }

                    Pins.Add(fdp);
                }
            }
        }
Exemplo n.º 31
0
        private void DisplayDebugInformation(IMoniker moniker, Guid filterClsid)
        {
            IPropertyBag propertyBag = null;

              try
              {
            string registryPath = string.Format(@"HKEY_CLASSES_ROOT\CLSID\{0}\InprocServer32", filterClsid.ToString("B"));
            string filterLocation = (string)Registry.GetValue(registryPath, string.Empty, string.Empty);

            object o;
            Guid IID_IPropertyBag = typeof(IPropertyBag).GUID;

            moniker.BindToStorage(null, null, ref IID_IPropertyBag, out o);
            propertyBag = (IPropertyBag)o;

            int hr = propertyBag.Read("FriendlyName", out o, null);
            Marshal.ThrowExceptionForHR(hr);

            string friendlyName = o.ToString();

            Debug.WriteLine(string.Format("Localtion: {0}\r\nFriendly Name: {1}", filterLocation, friendlyName));
              }
              catch { }
              finally
              {
            if (propertyBag != null)
              Marshal.ReleaseComObject(propertyBag);
              }
        }
Exemplo n.º 32
0
 public static string GetFriendlyName(IMoniker mon)
 {
   if (mon == null)
   {
     return string.Empty;
   }
   object bagObj = null;
   IPropertyBag bag = null;
   try
   {
     IErrorLog errorLog = null;
     Guid bagId = typeof (IPropertyBag).GUID;
     mon.BindToStorage(null, null, ref bagId, out bagObj);
     bag = (IPropertyBag)bagObj;
     object val = "";
     int hr = bag.Read("FriendlyName", out val, errorLog);
     if (hr != 0)
     {
       Marshal.ThrowExceptionForHR(hr);
     }
     string ret = val as string;
     if ((ret == null) || (ret.Length < 1))
     {
       throw new NotImplementedException("Device FriendlyName");
     }
     return ret;
   }
   catch (Exception)
   {
     return null;
   }
   finally
   {
     bag = null;
     if (bagObj != null)
     {
       ReleaseComObject(bagObj);
     }
     bagObj = null;
   }
 }