Ejemplo n.º 1
2
		public static bool GetDevicesOfCat( Guid cat, out ArrayList devs )
		{
			devs = null;
			int hr;
			object comObj = null;
			ICreateDevEnum enumDev = null;
			UCOMIEnumMoniker enumMon = null;
			UCOMIMoniker[] mon = new UCOMIMoniker[1];
            
			try {
				Type	srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
				if( srvType == null )
					throw new NotImplementedException( "System Device Enumerator" );

				comObj = Activator.CreateInstance( srvType );
				enumDev = (ICreateDevEnum) comObj;
				hr = enumDev.CreateClassEnumerator( ref cat, out enumMon, 0 );
				if( hr != 0 )
					throw new NotSupportedException( "No devices of the category" );

				int f, count = 0;
				do
				{
					hr = enumMon.Next( 1, mon, out f );
					if( (hr != 0) || (mon[0] == null) )
						break;
					DsDevice dev = new DsDevice();
					dev.Name = GetFriendlyName( mon[0] );
					if( devs == null )
						devs = new ArrayList();
					dev.Mon = mon[0]; mon[0] = null;
					devs.Add( dev ); dev = null;
					count++;
				}
				while(true);

				return count > 0;
			}
			catch( Exception )
			{
				if( devs != null )
				{
					foreach( DsDevice d in devs )
						d.Dispose();
					devs = null;
				}
				return false;
			}
			finally
			{
				enumDev = null;
				if( mon[0] != null )
					Marshal.ReleaseComObject( mon[0] ); mon[0] = null;
				if( enumMon != null )
					Marshal.ReleaseComObject( enumMon ); enumMon = null;
				if( comObj != null )
					Marshal.ReleaseComObject( comObj ); comObj = null;
			}

		}
        public static Hashtable GetRunningObjectTable()
        {
            Hashtable result = new Hashtable();

            int numFetched;
            UCOMIRunningObjectTable runningObjectTable;   
            UCOMIEnumMoniker monikerEnumerator;
            UCOMIMoniker[] monikers = new UCOMIMoniker[1];

            GetRunningObjectTable(0, out runningObjectTable);    
            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();          
            
            while (monikerEnumerator.Next(1, monikers, out numFetched) == 0)
            {     
                UCOMIBindCtx ctx;
                CreateBindCtx(0, out ctx);     
                    
                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);

                object runningObjectVal;  
                runningObjectTable.GetObject( monikers[0], out runningObjectVal); 

                result[ runningObjectName ] = runningObjectVal;
            } 

            return result;
        }
Ejemplo n.º 3
0
        // Token: 0x06000280 RID: 640 RVA: 0x000128C8 File Offset: 0x00010AC8
        private static string GetFriendlyName(UCOMIMoniker mon)
        {
            object obj = null;
            string result;

            try
            {
                Guid guid = typeof(IPropertyBag).GUID;
                mon.BindToStorage(null, null, ref guid, out obj);
                IPropertyBag propertyBag = (IPropertyBag)obj;
                object       obj2        = "";
                int          num         = propertyBag.Read("FriendlyName", ref obj2, IntPtr.Zero);
                string       text        = obj2 as string;
                result = text;
            }
            catch (Exception ex)
            {
                result = null;
            }
            finally
            {
                if (obj != null)
                {
                    Marshal.ReleaseComObject(RuntimeHelpers.GetObjectValue(obj));
                }
                obj = null;
            }
            return(result);
        }
Ejemplo n.º 4
0
        private IBaseFilter FindCaptureDevice()
        {
            Debug.WriteLine("Start the Sub FindCaptureDevice");
            int hr = 0;
            UCOMIEnumMoniker classEnum = null;

            UCOMIMoniker[] moniker = new UCOMIMoniker[1];
            object         source  = null;
            ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum();

            hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, CDef.None);
            Debug.WriteLine("Create an enumerator for the video capture devices : " + DsError.GetErrorText(hr));
            DsError.ThrowExceptionForHR(hr);
            Marshal.ReleaseComObject(devEnum);
            if (classEnum == null)
            {
                throw new ApplicationException("No video capture device was detected.\\r\\n\\r\\n" + "This sample requires a video capture device, such as a USB WebCam,\\r\\n" + "to be installed and working properly.  The sample will now close.");
            }
            int celt = 0;

            if (classEnum.Next(moniker.Length, moniker, out celt) == 0)
            {
                Guid iid = typeof(IBaseFilter).GUID;
                moniker[0].BindToObject(null, null, ref iid, out source);
            }
            else
            {
                throw new ApplicationException("Unable to access video capture device!");
            }
            Marshal.ReleaseComObject(moniker[0]);
            Marshal.ReleaseComObject(classEnum);
            return((IBaseFilter)source);
        }
Ejemplo n.º 5
0
        // Token: 0x0600033D RID: 829 RVA: 0x000138B8 File Offset: 0x00011AB8
        protected string getName(string monikerString)
        {
            UCOMIMoniker ucomimoniker  = null;
            UCOMIMoniker ucomimoniker2 = null;
            string       name;

            try
            {
                ucomimoniker = this.getAnyMoniker();
                int num;
                ucomimoniker.ParseDisplayName(null, null, monikerString, out num, out ucomimoniker2);
                name = this.getName(ucomimoniker);
            }
            finally
            {
                if (ucomimoniker != null)
                {
                    Marshal.ReleaseComObject(ucomimoniker);
                }
                ucomimoniker = null;
                if (ucomimoniker2 != null)
                {
                    Marshal.ReleaseComObject(ucomimoniker2);
                }
                ucomimoniker2 = null;
            }
            return(name);
        }
Ejemplo n.º 6
0
        // Token: 0x0600033B RID: 827 RVA: 0x000137F0 File Offset: 0x000119F0
        protected string getMonikerString(UCOMIMoniker moniker)
        {
            string result;

            moniker.GetDisplayName(null, null, out result);
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary> Получает читаемое имя фильтра с помощью его moniker</summary>
        protected string GetName(UCOMIMoniker moniker)
        {
            object       bagObj = null;
            IPropertyBag bag;

            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
            {
                if (bagObj != null)
                {
                    Marshal.ReleaseComObject(bagObj);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary> Get a moniker's human-readable name based on a moniker string. </summary>
        protected string getName(string monikerString)
        {
#if DSHOWNET
            UCOMIMoniker parser  = null;
            UCOMIMoniker moniker = null;
#else
#if VS2003
            UCOMIMoniker parser  = null;
            UCOMIMoniker moniker = null;
#else
            IMoniker parser  = null;
            IMoniker moniker = null;
#endif
#endif
            try
            {
                parser = getAnyMoniker();
                int eaten;
                parser.ParseDisplayName(null, null, monikerString, out eaten, out moniker);
                return(getName(parser));
            }
            finally
            {
                if (parser != null)
                {
                    Marshal.ReleaseComObject(parser);
                }
                parser = null;
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
                moniker = null;
            }
        }
Ejemplo n.º 9
0
		private static string GetFriendlyName( UCOMIMoniker mon )
		{
			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( "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 null;
			}
			finally
			{
				bag = null;
				if( bagObj != null )
					Marshal.ReleaseComObject( bagObj ); bagObj = null;
			}
		}
Ejemplo n.º 10
0
        // Get moniker string of the moniker
        private string GetMonikerString(UCOMIMoniker moniker)
        {
            string str;

            moniker.GetDisplayName(null, null, out str);
            return(str);
        }
Ejemplo n.º 11
0
        /// <summary> create the user selected capture device. </summary>
        bool CreateCaptureDevice(UCOMIMoniker mon)

        {
            object capObj = null;

            try
            {
                Guid gbf = typeof(IBaseFilter).GUID;
                mon.BindToObject(null, null, ref gbf, out capObj);
                capFilter = (IBaseFilter)capObj; capObj = null;
                return(true);
            }
            catch (Exception ee)
            {
                MessageBox.Show(this, "Could not create capture device\r\n" + ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            finally
            {
                if (capObj != null)
                {
                    Marshal.ReleaseComObject(capObj);
                }
                capObj = null;
            }
        }
Ejemplo n.º 12
0
        /// <summary> start all the interfaces, graphs and preview window. </summary>
        private bool StartupVideo(UCOMIMoniker mon)
        {
            int hr;

            if (!CreateCaptureDevice(mon))
            {
                return(false);
            }

            if (!GetInterfaces())
            {
                return(false);
            }

            if (!SetupGraph())
            {
                return(false);
            }

            hr = _mediaCtrl.Run();
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // will thow up input for tuner settings.
            //bool hasTuner = DsUtils.ShowTunerPinDialog( _capGraphBuilder2, _capFilter,this._viewControl.Handle );

            return(true);
        }
Ejemplo n.º 13
0
        /// <summary> Retrieve the a moniker's display name (i.e. it's unique string) </summary>
        protected string GetMonikerString(UCOMIMoniker moniker)
        {
            string s;

            moniker.GetDisplayName(null, null, out s);
            return(s);
        }
Ejemplo n.º 14
0
        private void StartupVideo(UCOMIMoniker mon)
        {
            int hr;

            try
            {
                GetInterfaces();

                CreateCaptureDevice(mon);

                SetupGraph();

                hr = mediaCtrl.Run();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                sampGrabber.SetCallback(this, 1);
            }
            catch (Exception ee)
            {
                throw new GoblinException("Could not start video stream\r\n" + ee.Message);
            }
        }
Ejemplo n.º 15
0
        /// <summary> Retrieve the human-readable name of the filter </summary>
        protected string GetName(UCOMIMoniker 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);

                var ret = val as string;

                if (string.IsNullOrEmpty(ret))
                    throw new NotImplementedException("Device FriendlyName");
                return (ret);
            }
            catch (Exception)
            {
                return ("");
            }
            finally
            {
                bag = null;
                if (bagObj != null)
                    Marshal.ReleaseComObject(bagObj); bagObj = null;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// create the user selected capture device.
        /// </summary>
        private void CreateCaptureDevice(UCOMIMoniker mon)
        {
            object capObj = null;
            String errMsg = "";

            try
            {
                Guid gbf = typeof(IBaseFilter).GUID;
                mon.BindToObject(null, null, ref gbf, out capObj);
                capFilter = (IBaseFilter)capObj; capObj = null;
            }
            catch (Exception ee)
            {
                errMsg = ee.Message;
            }
            finally
            {
                if (capObj != null)
                {
                    Marshal.ReleaseComObject(capObj);
                }
                capObj = null;
            }

            if (errMsg.Length > 0)
            {
                throw new GoblinException("Could not create capture device\r\n" + errMsg);
            }
        }
        private static ArrayList GetMSDEVFromGIT()
        {
            ArrayList tmp = new ArrayList();
            UCOMIRunningObjectTable prot;
            UCOMIEnumMoniker        pMonkEnum;

            try
            {
                GetRunningObjectTable(0, out prot);
                prot.EnumRunning(out pMonkEnum);
                pMonkEnum.Reset();                 // Churn through enumeration.
                int             fetched;
                UCOMIMoniker [] pmon = new UCOMIMoniker[1];
                while (pMonkEnum.Next(1, pmon, out fetched) == 0)
                {
                    UCOMIBindCtx pCtx;
                    CreateBindCtx(0, out pCtx);
                    string str;
                    pmon[0].GetDisplayName(pCtx, null, out str);
                    if (str.IndexOf("VisualStudio.DTE") != -1)
                    {
                        object objReturnObject;
                        prot.GetObject(pmon[0], out objReturnObject);
                        tmp.Add(objReturnObject);
                    }
                }
            }
            catch
            {
            }
            return(tmp);
        }
Ejemplo n.º 18
0
        protected string getName(string monikerString)
        {
            UCOMIMoniker moniker = null;
            UCOMIMoniker ppmkOut = null;
            string       str;

            try
            {
                int num;
                moniker = this.getAnyMoniker();
                moniker.ParseDisplayName(null, null, monikerString, out num, out ppmkOut);
                str = this.getName(moniker);
            }
            finally
            {
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
                moniker = null;
                if (ppmkOut != null)
                {
                    Marshal.ReleaseComObject(ppmkOut);
                }
                ppmkOut = null;
            }
            return(str);
        }
Ejemplo n.º 19
0
        /// <summary> Get a moniker's human-readable name based on a moniker string. </summary>
        protected string GetName(string monikerString)
        {
            UCOMIMoniker parser  = null;
            UCOMIMoniker moniker = null;

            try
            {
                parser = GetAnyMoniker();
                int eaten;
                parser.ParseDisplayName(null, null, monikerString, out eaten, out moniker);
                return(GetName(parser));
            }
            finally
            {
                if (parser != null)
                {
                    Marshal.ReleaseComObject(parser);
                }
                parser = null;
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
                moniker = null;
            }
        }
Ejemplo n.º 20
0
        // This version of FindCaptureDevice is provide for education only.
        // A second version using the DsDevice helper class is define later.
        public IBaseFilter FindCaptureDevice()
        {
            int hr = 0;

#if USING_NET11
            UCOMIEnumMoniker classEnum = null;
            UCOMIMoniker[]   moniker   = new UCOMIMoniker[1];
#else
            IEnumMoniker classEnum = null;
            IMoniker[]   moniker   = new IMoniker[1];
#endif
            object source = null;

            // Create the system device enumerator
            ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum();

            // Create an enumerator for the video capture devices
            hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, 0);
            DsError.ThrowExceptionForHR(hr);

            // The device enumerator is no more needed
            Marshal.ReleaseComObject(devEnum);

            // If there are no enumerators for the requested type, then
            // CreateClassEnumerator will succeed, but classEnum will be NULL.
            if (classEnum == null)
            {
                throw new ApplicationException("No video capture device was detected.\r\n\r\n" +
                                               "This sample requires a video capture device, such as a USB WebCam,\r\n" +
                                               "to be installed and working properly.  The sample will now close.");
            }

            // Use the first video capture device on the device list.
            // Note that if the Next() call succeeds but there are no monikers,
            // it will return 1 (S_FALSE) (which is not a failure).  Therefore, we
            // check that the return code is 0 (S_OK).
#if USING_NET11
            int i;
            if (classEnum.Next(moniker.Length, moniker, IntPtr.Zero) == 0)
#else
            if (classEnum.Next(moniker.Length, moniker, IntPtr.Zero) == 0)
#endif
            {
                // Bind Moniker to a filter object
                Guid iid = typeof(IBaseFilter).GUID;
                moniker[0].BindToObject(null, null, ref iid, out source);
            }
            else
            {
                throw new ApplicationException("Unable to access video capture device!");
            }

            // Release COM objects
            Marshal.ReleaseComObject(moniker[0]);
            Marshal.ReleaseComObject(classEnum);

            // An exception is thrown if cast fail
            return((IBaseFilter)source);
        }
Ejemplo n.º 21
0
 public void Dispose()
 {
     if (this.Mon != null)
     {
         Marshal.ReleaseComObject(this.Mon);
     }
     this.Mon = null;
 }
 public void Dispose()
 {
     if (Mon != null)
     {
         Marshal.ReleaseComObject(Mon);
     }
     Mon = null;
 }
Ejemplo n.º 23
0
        /// <summary> 
        /// Populate the InnerList with a list of filters from a particular category 
        /// </summary>
        protected void GetFilters(Guid category)
        {
            int hr;
            object comObj = null;
            ICreateDevEnum enumDev = null;
            UCOMIEnumMoniker enumMon = null;
            var mon = new UCOMIMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID(Uuid.Clsid.SystemDeviceEnum);
                if (srvType == null)
                    throw new NotImplementedException("System Device Enumerator");
                comObj = Activator.CreateInstance(srvType);
                enumDev = (ICreateDevEnum)comObj;

                // Create an enumerator to find filters in category
                hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0);
                if (hr != 0)
                    return;
                    //throw new NotSupportedException("No devices of the category");


                // Loop through the enumerator
                int f;

                do
                {
                    // Next filter
                    hr = enumMon.Next(1, mon, out f);

                    if ((hr != 0) || (mon[0] == null))
                        break;

                    // Add the filter
                    var filter = new Filter(mon[0]);
                    InnerList.Add(filter);

                    // Release resources
                    Marshal.ReleaseComObject(mon[0]);
                    mon[0] = null;
                } while (true);

                // Sort
                InnerList.Sort();
            }
            finally
            {
                enumDev = null;
                if (mon[0] != null)
                    Marshal.ReleaseComObject(mon[0]); mon[0] = null;
                if (enumMon != null)
                    Marshal.ReleaseComObject(enumMon); enumMon = null;
                if (comObj != null)
                    Marshal.ReleaseComObject(comObj); comObj = null;
            }
        }
Ejemplo n.º 24
0
        protected void CalcRunningObjName(UCOMIRunningObjectTable rot,
                                          UCOMIBindCtx bc,
                                          UCOMIMoniker moniker,
                                          String monikerName)
        {
            _moniker     = moniker;
            _monikerName = monikerName;
            // FIXME - Does not work because IsRunning is defined
            // incorrectly in the IRunningObjectTable mapping
            //IsRunning = rot.IsRunning(Moniker);

            // Get the object from the table
            _isRunningObjectTable = true;
            // Persist Guid is probably not used for anything, but
            // let's get it anyway
            Guid persistGuid = new Guid();

            _moniker.GetClassID(out persistGuid);
            _persistGuid = persistGuid;
            // GUID is the *real* CLSID for the object
            String rotProgId = null;

            if (_monikerName.StartsWith("!{"))
            {
                int guidStart = _monikerName.IndexOf('{');
                int guidEnd   = _monikerName.IndexOf('}');
                if (guidStart != -1 && guidEnd != -1)
                {
                    _CLSID =
                        _monikerName.Substring(guidStart, guidEnd);
                    _classIdKey = Windows.KeyCLSID.OpenSubKey(_CLSID);
                    if (_classIdKey != null)
                    {
                        String progId = (String)
                                        _classIdKey.OpenSubKey("ProgID").
                                        GetValue(null);
                        _classNameKey =
                            Windows.KeyClassRoot.OpenSubKey(progId);
                        rotProgId = progId
                                    + _monikerName.Substring(guidEnd + 1);
                    }
                }
                // Use the translated progId if available
                if (rotProgId != null)
                {
                    _monikerDisplayName = rotProgId;
                }
                else
                {
                    _monikerDisplayName = _monikerName;
                }
            }
            else
            {
                // The moniker is something else, just use that
                _monikerDisplayName = _monikerName;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        ///  This method gets a UCOMIMoniker object.
        ///
        ///  HACK: The only way to create a UCOMIMoniker from a moniker
        ///  string is to use UCOMIMoniker.ParseDisplayName(). So I
        ///  need ANY UCOMIMoniker object so that I can call
        ///  ParseDisplayName(). Does anyone have a better solution?
        ///
        ///  This assumes there is at least one video compressor filter
        ///  installed on the system.
        /// </summary>
        protected UCOMIMoniker GetAnyMoniker()
        {
            Guid             category = Uuid.FilterCategory.VideoCompressorCategory;
            int              hr;
            object           comObj  = null;
            ICreateDevEnum   enumDev = null;
            UCOMIEnumMoniker enumMon = null;

            UCOMIMoniker[] mon = new UCOMIMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID(Uuid.Clsid.SystemDeviceEnum);
                if (srvType == null)
                {
                    throw new NotImplementedException("System Device Enumerator");
                }
                comObj  = Activator.CreateInstance(srvType);
                enumDev = (ICreateDevEnum)comObj;

                //Create an enumerator to find filters in category
                hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0);
                if (hr != 0)
                {
                    throw new NotSupportedException("No devices of the category");
                }

                // Get first filter
                int f;
                hr = enumMon.Next(1, mon, out f);
                if ((hr != 0))
                {
                    mon[0] = null;
                }

                return(mon[0]);
            }
            finally
            {
                enumDev = null;
                if (enumMon != null)
                {
                    Marshal.ReleaseComObject(enumMon);
                }
                enumMon = null;
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
Ejemplo n.º 26
0
        // Token: 0x06000341 RID: 833 RVA: 0x00013A08 File Offset: 0x00011C08
        protected void getFilters(Guid category)
        {
            object           obj = null;
            UCOMIEnumMoniker ucomienumMoniker = null;

            UCOMIMoniker[] array = new UCOMIMoniker[1];
            try
            {
                Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
                obj = RuntimeHelpers.GetObjectValue(Activator.CreateInstance(typeFromCLSID));
                ICreateDevEnum createDevEnum = (ICreateDevEnum)obj;
                int            num           = createDevEnum.CreateClassEnumerator(ref category, out ucomienumMoniker, 0);
                if (num != 0)
                {
                }
                for (;;)
                {
                    int num2;
                    num = ucomienumMoniker.Next(1, array, out num2);
                    if (num != 0)
                    {
                        break;
                    }
                    if (array[0] == null)
                    {
                        break;
                    }
                    Filter value = new Filter(array[0]);
                    this.InnerList.Add(value);
                    Marshal.ReleaseComObject(array[0]);
                    array[0] = null;
                }
                this.InnerList.Sort();
            }
            finally
            {
                if (array[0] != null)
                {
                    Marshal.ReleaseComObject(array[0]);
                }
                array[0] = null;
                if (ucomienumMoniker != null)
                {
                    Marshal.ReleaseComObject(ucomienumMoniker);
                }
                ucomienumMoniker = null;
                if (obj != null)
                {
                    Marshal.ReleaseComObject(RuntimeHelpers.GetObjectValue(obj));
                }
                obj = null;
            }
        }
Ejemplo n.º 27
0
        protected void getFilters(Guid category)
        {
            object           o             = null;
            ICreateDevEnum   enum2         = null;
            UCOMIEnumMoniker ppEnumMoniker = null;

            UCOMIMoniker[] rgelt = new UCOMIMoniker[1];
            try
            {
                int  num;
                Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
                if (typeFromCLSID == null)
                {
                    throw new NotImplementedException("System Device Enumerator");
                }
                o     = Activator.CreateInstance(typeFromCLSID);
                enum2 = (ICreateDevEnum)o;
                if (enum2.CreateClassEnumerator(ref category, out ppEnumMoniker, 0) != 0)
                {
                    throw new NotSupportedException("No devices of the category");
                }
                while ((ppEnumMoniker.Next(1, rgelt, out num) == 0) && (rgelt[0] != null))
                {
                    Filter filter = new Filter(rgelt[0]);
                    base.InnerList.Add(filter);
                    Marshal.ReleaseComObject(rgelt[0]);
                    rgelt[0] = null;
                }
                base.InnerList.Sort();
            }
            finally
            {
                enum2 = null;
                if (rgelt[0] != null)
                {
                    Marshal.ReleaseComObject(rgelt[0]);
                }
                rgelt[0] = null;
                if (ppEnumMoniker != null)
                {
                    Marshal.ReleaseComObject(ppEnumMoniker);
                }
                ppEnumMoniker = null;
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                }
                o = null;
            }
        }
Ejemplo n.º 28
0
 protected void getFilters(Guid category)
 {
     object o = null;
     ICreateDevEnum enum2 = null;
     UCOMIEnumMoniker ppEnumMoniker = null;
     UCOMIMoniker[] rgelt = new UCOMIMoniker[1];
     try
     {
         int num2;
         Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
         if (typeFromCLSID == null)
         {
             throw new NotImplementedException("System Device Enumerator");
         }
         o = Activator.CreateInstance(typeFromCLSID);
         enum2 = (ICreateDevEnum) o;
         if (enum2.CreateClassEnumerator(ref category, out ppEnumMoniker, 0) != 0)
         {
             throw new NotSupportedException("No devices of the category");
         }
         while ((ppEnumMoniker.Next(1, rgelt, out num2) == 0) && (rgelt[0] != null))
         {
             DirectX.Capture.Filter filter = new DirectX.Capture.Filter(rgelt[0]);
             base.InnerList.Add(filter);
             Marshal.ReleaseComObject(rgelt[0]);
             rgelt[0] = null;
         }
         base.InnerList.Sort();
     }
     finally
     {
         enum2 = null;
         if (rgelt[0] != null)
         {
             Marshal.ReleaseComObject(rgelt[0]);
         }
         rgelt[0] = null;
         if (ppEnumMoniker != null)
         {
             Marshal.ReleaseComObject(ppEnumMoniker);
         }
         ppEnumMoniker = null;
         if (o != null)
         {
             Marshal.ReleaseComObject(o);
         }
         o = null;
     }
 }
Ejemplo n.º 29
0
        /// <summary>
        ///  Получает объект типа UCOMIMoniker.
        ///  Требуется хотя бы один видеокомпрессор в системе
        /// </summary>
        protected UCOMIMoniker GetAnyMoniker()
        {
            Guid             category = FilterCategory.VideoCompressorCategory;
            int              hr;
            object           comObj = null;
            ICreateDevEnum   enumDev;
            UCOMIEnumMoniker enumMon = null;

            UCOMIMoniker[] mon = new UCOMIMoniker[1];

            try
            {
                //Получаем system device enumerator
                Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
                if (srvType == null)
                {
                    throw new NotImplementedException("System Device Enumerator");
                }
                comObj  = Activator.CreateInstance(srvType);
                enumDev = (ICreateDevEnum)comObj;

                //Создаем enumerator чтобы найти фильтры в категории
                hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0);
                if (hr != 0)
                {
                    throw new NotSupportedException("No devices of the category");
                }

                //Получаем первый фильтр
                hr = enumMon.Next(1, mon, out _);
                if ((hr != 0))
                {
                    mon[0] = null;
                }

                return(mon[0]);
            }
            finally
            {
                if (enumMon != null)
                {
                    Marshal.ReleaseComObject(enumMon);
                }
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
            }
        }
Ejemplo n.º 30
0
        public static bool AddGraphToRot(object graph, out int cookie)
        {
            bool flag;

            cookie = 0;
            int errorCode = 0;
            UCOMIRunningObjectTable pprot = null;
            UCOMIMoniker            ppmk  = null;

            try
            {
                errorCode = GetRunningObjectTable(0, out pprot);
                if (errorCode < 0)
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
                int    currentProcessId  = GetCurrentProcessId();
                IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(graph);
                int    num3 = (int)iUnknownForObject;
                Marshal.Release(iUnknownForObject);
                string item = string.Format("FilterGraph {0} pid {1}", num3.ToString("x8"), currentProcessId.ToString("x8"));
                errorCode = CreateItemMoniker("!", item, out ppmk);
                if (errorCode < 0)
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
                pprot.Register(1, graph, ppmk, out cookie);
                flag = true;
            }
            catch (Exception)
            {
                flag = false;
            }
            finally
            {
                if (ppmk != null)
                {
                    Marshal.ReleaseComObject(ppmk);
                }
                ppmk = null;
                if (pprot != null)
                {
                    Marshal.ReleaseComObject(pprot);
                }
                pprot = null;
            }
            return(flag);
        }
Ejemplo n.º 31
0
        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 == null)
            {
                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 != null)
                {
                    Marshal.ReleaseComObject(bindCtx);
                }
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
            }

            return(filter);
        }
Ejemplo n.º 32
0
        /// <summary> start all the interfaces, graphs and preview window. </summary>
        bool StartupVideo(UCOMIMoniker mon)

        {
            int hr;

            try
            {
                if (!CreateCaptureDevice(mon))
                {
                    return(false);
                }

                if (!GetInterfaces())
                {
                    return(false);
                }

                if (!SetupGraph())
                {
                    return(false);
                }

                if (!SetupVideoWindow())
                {
                    return(false);
                }

                 #if DEBUG
                DsROT.AddGraphToRot(graphBuilder, out rotCookie);               // graphBuilder capGraph
                   #endif

                hr = mediaCtrl.Run();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                bool hasTuner = DsUtils.ShowTunerPinDialog(capGraph, capFilter, this.Handle);
                // toolBarBtnTune.Enabled = hasTuner;

                return(true);
            }
            catch (Exception ee)
            {
                MessageBox.Show(this, "Could not start video stream\r\n" + ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
        }
Ejemplo n.º 33
0
        /// <summary> start all the interfaces, graphs and preview window. </summary>
        bool StartupVideo(UCOMIMoniker mon)
        {
            int hr;

            try
            {
                if (!CreateCaptureDevice(mon))
                {
                    return(false);
                }

                if (!GetInterfaces())
                {
                    return(false);
                }

                if (!SetupGraph())
                {
                    return(false);
                }

                if (!SetupVideoWindow())
                {
                    return(false);
                }

#if DEBUG
                //DsROT.AddGraphToRot( graphBuilder, out rotCookie );		// graphBuilder capGraph
                rot = new DsROTEntry(graphBuilder);
#endif

                hr = mediaCtrl.Run();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                bool hasTuner = DsUtils.ShowTunerPinDialog(capGraph, capFilter, this.Handle);
                //tuneBtn.Enabled = hasTuner;

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 34
0
        /// <summary> start all the interfaces, graphs and preview window. </summary>
        bool StartupVideo(UCOMIMoniker mon)
        {
            int hr;

            try
            {
                if (!CreateCaptureDevice(mon))
                {
                    return(false);
                }

                if (!GetInterfaces())
                {
                    return(false);
                }

                if (!SetupGraph())
                {
                    return(false);
                }

                if (!SetupVideoWindow())
                {
                    return(false);
                }

#if DEBUG
                DsROT.AddGraphToRot(graphBuilder, out rotCookie);       // graphBuilder capGraph
#endif

                hr = mediaCtrl.Run();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                CaptureImage(); // Begins updating...

                return(true);
            }
            catch (Exception ee)
            {
                MessageBox.Show(this, "Could not start video stream\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
        }
Ejemplo n.º 35
0
        public static bool AddGraphToRot(object graph, out int cookie)
        {
            cookie = 0;
            int hr = 0;
            UCOMIRunningObjectTable rot = null;
            UCOMIMoniker            mk  = null;

            try {
                hr = GetRunningObjectTable(0, out rot);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                int    id    = GetCurrentProcessId();
                IntPtr iuPtr = Marshal.GetIUnknownForObject(graph);
                int    iuInt = (int)iuPtr;
                Marshal.Release(iuPtr);
                string item = string.Format("FilterGraph {0} pid {1}", iuInt.ToString("x8"), id.ToString("x8"));
                hr = CreateItemMoniker("!", item, out mk);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                rot.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, graph, mk, out cookie);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (mk != null)
                {
                    Marshal.ReleaseComObject(mk);
                }
                mk = null;
                if (rot != null)
                {
                    Marshal.ReleaseComObject(rot);
                }
                rot = null;
            }
        }
Ejemplo n.º 36
0
        protected UCOMIMoniker getAnyMoniker()
        {
            UCOMIMoniker     moniker;
            Guid             videoCompressorCategory = FilterCategory.VideoCompressorCategory;
            object           o             = null;
            ICreateDevEnum   enum2         = null;
            UCOMIEnumMoniker ppEnumMoniker = null;

            UCOMIMoniker[] rgelt = new UCOMIMoniker[1];
            try
            {
                int  num;
                Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
                if (typeFromCLSID == null)
                {
                    throw new NotImplementedException("System Device Enumerator");
                }
                o     = Activator.CreateInstance(typeFromCLSID);
                enum2 = (ICreateDevEnum)o;
                if (enum2.CreateClassEnumerator(ref videoCompressorCategory, out ppEnumMoniker, 0) != 0)
                {
                    throw new NotSupportedException("No devices of the category");
                }
                if (ppEnumMoniker.Next(1, rgelt, out num) != 0)
                {
                    rgelt[0] = null;
                }
                moniker = rgelt[0];
            }
            finally
            {
                enum2 = null;
                if (ppEnumMoniker != null)
                {
                    Marshal.ReleaseComObject(ppEnumMoniker);
                }
                ppEnumMoniker = null;
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                }
                o = null;
            }
            return(moniker);
        }
Ejemplo n.º 37
0
 protected UCOMIMoniker getAnyMoniker()
 {
     UCOMIMoniker moniker2;
     Guid videoCompressorCategory = FilterCategory.VideoCompressorCategory;
     object o = null;
     ICreateDevEnum enum2 = null;
     UCOMIEnumMoniker ppEnumMoniker = null;
     UCOMIMoniker[] rgelt = new UCOMIMoniker[1];
     try
     {
         int num2;
         Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
         if (typeFromCLSID == null)
         {
             throw new NotImplementedException("System Device Enumerator");
         }
         o = Activator.CreateInstance(typeFromCLSID);
         enum2 = (ICreateDevEnum) o;
         if (enum2.CreateClassEnumerator(ref videoCompressorCategory, out ppEnumMoniker, 0) != 0)
         {
             throw new NotSupportedException("No devices of the category");
         }
         if (ppEnumMoniker.Next(1, rgelt, out num2) != 0)
         {
             rgelt[0] = null;
         }
         moniker2 = rgelt[0];
     }
     finally
     {
         enum2 = null;
         if (ppEnumMoniker != null)
         {
             Marshal.ReleaseComObject(ppEnumMoniker);
         }
         ppEnumMoniker = null;
         if (o != null)
         {
             Marshal.ReleaseComObject(o);
         }
         o = null;
     }
     return moniker2;
 }
Ejemplo n.º 38
0
		public static int GetRunningObjectCount()
		{
			int count = 0;
			UCOMIBindCtx bc;
			UCOMIRunningObjectTable rot;
			UCOMIEnumMoniker em;
			UCOMIMoniker[] moniker = new UCOMIMoniker[1];
			int unused;
			
			ActiveX.CreateBindCtx(0, out bc);
			bc.GetRunningObjectTable(out rot);
			rot.EnumRunning(out em);
			while (0 == em.Next(1, moniker, out unused))
				count++;
			Marshal.ReleaseComObject(bc);
			Marshal.ReleaseComObject(rot);
			Marshal.ReleaseComObject(em);
			return count;
		}
Ejemplo n.º 39
0
		// Get filter name represented by the moniker
		private string GetName(UCOMIMoniker 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;
				}
			}
		}
Ejemplo n.º 40
0
        // This version of FindCaptureDevice is provide for education only.
        // A second version using the DsDevice helper class is define later.
        public IBaseFilter FindCaptureDevice()
        {
            int hr = 0;
            #if USING_NET11
              UCOMIEnumMoniker classEnum = null;
              UCOMIMoniker[] moniker = new UCOMIMoniker[1];
            #else
              IEnumMoniker classEnum = null;
              IMoniker[] moniker = new IMoniker[1];
            #endif
              object source = null;

              // Create the system device enumerator
              ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum();

              // Create an enumerator for the video capture devices
              hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, 0);
              DsError.ThrowExceptionForHR(hr);

              // The device enumerator is no more needed
              Marshal.ReleaseComObject(devEnum);

              // If there are no enumerators for the requested type, then
              // CreateClassEnumerator will succeed, but classEnum will be NULL.
              if (classEnum == null)
              {
            throw new ApplicationException("No video capture device was detected.\r\n\r\n" +
                                       "This sample requires a video capture device, such as a USB WebCam,\r\n" +
                                       "to be installed and working properly.  The sample will now close.");
              }

              // Use the first video capture device on the device list.
              // Note that if the Next() call succeeds but there are no monikers,
              // it will return 1 (S_FALSE) (which is not a failure).  Therefore, we
              // check that the return code is 0 (S_OK).
            #if USING_NET11
              int i;
              if (classEnum.Next (moniker.Length, moniker, IntPtr.Zero) == 0)
            #else
              if (classEnum.Next (moniker.Length, moniker, IntPtr.Zero) == 0)
            #endif
              {
            // Bind Moniker to a filter object
            Guid iid = typeof(IBaseFilter).GUID;
            moniker[0].BindToObject(null, null, ref iid, out source);
              }
              else
              {
            throw new ApplicationException("Unable to access video capture device!");
              }

              // Release COM objects
              Marshal.ReleaseComObject(moniker[0]);
              Marshal.ReleaseComObject(classEnum);

              // An exception is thrown if cast fail
              return (IBaseFilter) source;
        }
Ejemplo n.º 41
0
        /// <summary>
        ///  This method gets a UCOMIMoniker object.
        /// 
        ///  HACK: The only way to create a UCOMIMoniker from a moniker 
        ///  string is to use UCOMIMoniker.ParseDisplayName(). So I 
        ///  need ANY UCOMIMoniker object so that I can call 
        ///  ParseDisplayName(). Does anyone have a better solution?
        /// 
        ///  This assumes there is at least one video compressor filter
        ///  installed on the system.
        /// </summary>
        protected UCOMIMoniker getAnyMoniker()
        {
            Guid				category = FilterCategory.VideoCompressorCategory;
            int					hr;
            object				comObj = null;
            ICreateDevEnum		enumDev = null;
            UCOMIEnumMoniker	enumMon = null;
            UCOMIMoniker[]		mon = new UCOMIMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
                if( srvType == null )
                    throw new NotImplementedException( "System Device Enumerator" );
                comObj = Activator.CreateInstance( srvType );
                enumDev = (ICreateDevEnum) comObj;

                // Create an enumerator to find filters in category
                hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
                if( hr != 0 )
                    throw new NotSupportedException( "No devices of the category" );

                // Get first filter
                int f;
                hr = enumMon.Next( 1, mon, out f );
                if( (hr != 0) )
                    mon[0] = null;

                return( mon[0] );
            }
            finally
            {
                enumDev = null;
                if( enumMon != null )
                    Marshal.ReleaseComObject( enumMon ); enumMon = null;
                if( comObj != null )
                    Marshal.ReleaseComObject( comObj ); comObj = null;
            }
        }
Ejemplo n.º 42
0
 /// <summary> Create a new filter from its moniker </summary>
 internal Filter( UCOMIMoniker moniker )
 {
     Name = getName( moniker );
     MonikerString = getMonikerString( moniker );
 }
Ejemplo n.º 43
0
 /// <summary> Retrieve the a moniker's display name (i.e. it's unique string) </summary>
 protected string getMonikerString(UCOMIMoniker moniker)
 {
     string s;
     moniker.GetDisplayName( null, null, out s );
     return( s );
 }
Ejemplo n.º 44
0
 /// <summary> create the user selected capture device. </summary>
 private bool CreateCaptureDevice( UCOMIMoniker mon )
 {
     object capObj = null;
     try
     {
         Guid gbf = typeof( IBaseFilter ).GUID;
         mon.BindToObject( null, null, ref gbf, out capObj );
         capFilter = (IBaseFilter) capObj; capObj = null;
         return true;
     }
     catch( Exception ee )
     {
         if( capObj != null )
             Marshal.ReleaseComObject( capObj ); capObj = null;
         throw ee;
     }
 }
Ejemplo n.º 45
0
 internal Filter(UCOMIMoniker moniker)
 {
     this.Name = this.getName(moniker);
     this.MonikerString = this.getMonikerString(moniker);
 }
        /// <summary>
        /// Get a snapshot of the running object table (ROT).
        /// </summary>
        /// <returns>A hashtable mapping the name of the object
        //     in the ROT to the corresponding object</returns>
        public Hashtable GetRunningObjectTable()
        {
            Hashtable result = new Hashtable();

            int numFetched;
            UCOMIRunningObjectTable runningObjectTable;
            UCOMIEnumMoniker monikerEnumerator;
            UCOMIMoniker[] monikers = new UCOMIMoniker[1];

            GetRunningObjectTable(0, out runningObjectTable);
            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();

            while (monikerEnumerator.Next(1, monikers, out numFetched) == 0)
            {
                UCOMIBindCtx ctx;
                CreateBindCtx(0, out ctx);

                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);

                object runningObjectVal;
                runningObjectTable.GetObject(monikers[0], out runningObjectVal);

                result[runningObjectName] = runningObjectVal;
            }

            return result;
        }
Ejemplo n.º 47
0
        /// <summary> start all the interfaces, graphs and preview window. </summary>
        bool StartupVideo( UCOMIMoniker mon )
        {
            int hr;
            try {
            if( ! CreateCaptureDevice( mon ) )
                return false;

            if( ! GetInterfaces() )
                return false;

            if( ! SetupGraph() )
                return false;

            if( ! SetupVideoWindow() )
                return false;

            #if DEBUG
                DsROT.AddGraphToRot( graphBuilder, out rotCookie );		// graphBuilder capGraph
            #endif

            hr = mediaCtrl.Run();
            if( hr < 0 )
                Marshal.ThrowExceptionForHR( hr );
            return true;
            }
            catch( Exception ee )
            {
            MessageBox.Show( this, "Could not start video stream\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
            return false;
            }
        }
Ejemplo n.º 48
0
 /// <summary> create the user selected capture device. </summary>
 bool CreateCaptureDevice( UCOMIMoniker mon )
 {
     object capObj = null;
     try {
     Guid gbf = typeof( IBaseFilter ).GUID;
     mon.BindToObject( null, null, ref gbf, out capObj );
     capFilter = (IBaseFilter) capObj; capObj = null;
     return true;
     }
     catch( Exception ee )
     {
     MessageBox.Show( this, "Could not create capture device\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
     return false;
     }
     finally
     {
     if( capObj != null )
         Marshal.ReleaseComObject( capObj ); capObj = null;
     }
 }
Ejemplo n.º 49
0
		internal Filter(UCOMIMoniker moniker )
Ejemplo n.º 50
0
		protected string getMonikerString(UCOMIMoniker moniker)
Ejemplo n.º 51
0
		protected string getName(UCOMIMoniker moniker)
		public static extern int MkParseDisplayName(UCOMIBindCtx pcb, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out int pchEaten, out UCOMIMoniker ppmk);
 public void OnRename(UCOMIMoniker pmk)
 {
     // TODO:  Add DocHostUIHandler.OnRename implementation
 }
Ejemplo n.º 54
0
        /// <summary> start all the interfaces, graphs and preview window. </summary>
        private bool StartupVideo( UCOMIMoniker mon )
        {
            int hr;
            if( ! CreateCaptureDevice( mon ) )
                return false;

            if( ! GetInterfaces() )
                return false;

            if( ! SetupGraph() )
                return false;

            hr = mediaCtrl.Run();
            if( hr < 0 )
                Marshal.ThrowExceptionForHR( hr );

            // will thow up input for tuner settings.
            //bool hasTuner = DsUtils.ShowTunerPinDialog( capGraph, capFilter, IntPtr.Zero );

            return true;
        }
Ejemplo n.º 55
0
        private static extern int CreateItemMoniker( string delim,
			string item, out UCOMIMoniker ppmk );
Ejemplo n.º 56
0
        protected IMoniker getAnyMoniker()
#endif
#endif
		{
			Guid				category = FilterCategory.VideoCompressorCategory;
			int					hr;
			object				comObj = null;
			ICreateDevEnum		enumDev = null;
#if DSHOWNET
			IEnumMoniker	enumMon = null;
			IMoniker[]		mon = new IMoniker[1];
#else
#if VS2003
			UCOMIEnumMoniker	enumMon = null;
			UCOMIMoniker[]		mon = new UCOMIMoniker[1];
#else
            IEnumMoniker enumMon = null;
            IMoniker[] mon = new IMoniker[1];
#endif
#endif

			try 
			{
				// Get the system device enumerator
#if DSHOWNET
				Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
				if( srvType == null )
					throw new NotImplementedException( "System Device Enumerator" );
				comObj = Activator.CreateInstance( srvType );
				enumDev = (ICreateDevEnum) comObj;

				// Create an enumerator to find filters in category
				hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
#else
                // Get the system device enumerator
                enumDev = (ICreateDevEnum)new DirectShowLib.CreateDevEnum();

                // Create an enumerator to find filters in category
                hr = enumDev.CreateClassEnumerator(category, out enumMon, CDef.None);
#endif
				if( hr != 0 )
					throw new NotSupportedException( "No devices of the category" );

				// Get first filter
#if DSHOWNET
				IntPtr f=IntPtr.Zero;
				hr = enumMon.Next( 1, mon, f );
#else
#if VS2003
				int f;
				hr = enumMon.Next( 1, mon, out f );
#else
                IntPtr f = IntPtr.Zero;
                hr = enumMon.Next(1, mon, f);
#endif
#endif
				if( (hr != 0) )
					mon[0] = null;

				return( mon[0] );
			}
			finally
			{
				enumDev = null;
				if( enumMon != null )
					Marshal.ReleaseComObject( enumMon ); enumMon = null;
				if( comObj != null )
					Marshal.ReleaseComObject( comObj ); comObj = null;
			}
		}
Ejemplo n.º 57
0
		/// <summary> Populate the InnerList with a list of filters from a particular category </summary>
		protected void getFilters(Guid category)
		{
			int					hr;
			object				comObj = null;
			ICreateDevEnum		enumDev = null;
#if DSHOWNET
			IEnumMoniker	enumMon = null;
			IMoniker[]		mon = new IMoniker[1];
#else
#if VS2003
			UCOMIEnumMoniker	enumMon = null;
			UCOMIMoniker[]		mon = new UCOMIMoniker[1];
#else
			IEnumMoniker	enumMon = null;
			IMoniker[]		mon = new IMoniker[1];
#endif
#endif

			try 
			{
#if DSHOWNET
				// Get the system device enumerator
				Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
				if( srvType == null )
					throw new NotImplementedException( "System Device Enumerator" );
				comObj = Activator.CreateInstance( srvType );
				enumDev = (ICreateDevEnum) comObj;

				// Create an enumerator to find filters in category
				hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
#else
				enumDev = (ICreateDevEnum) new CreateDevEnum();

				// Create an enumerator to find filters in category
				hr = enumDev.CreateClassEnumerator( category, out enumMon, 0 );
#endif
				if( hr != 0 )
//#if NEWCODE
				{
					if(category == FilterCategory.VideoInputDevice)
					{
                        MessageBox.Show("Warning No Video Input Devices");
                        return;
						//throw new NotSupportedException( "No devices of the category VideoInputDevice" );
					}
					else if(category == FilterCategory.AudioInputDevice)
					{
//						throw new NotSupportedException( "No devices of the category AudioInputDevice" );
                        return;
					}
					else if(category == FilterCategory.VideoCompressorCategory)
					{
                        MessageBox.Show("Warning No Video Input Devices");
                        return;
                        //throw new NotSupportedException("No devices of the category VideoCompressorCategory");
					}
					else
						if(category == FilterCategory.AudioCompressorCategory)
					{
						throw new NotSupportedException( "No devices of the category AudioCompressorCategory" );
					}
					else
					{
						throw new NotSupportedException( "No devices of the category " + category.ToString() );
					}
				}
//#else
//				throw new NotSupportedException( "No devices of the category" );
//#endif

				// Loop through the enumerator
#if DSHOWNET
				IntPtr f = IntPtr.Zero;
#else
#if VS2003
				int f = 0;
#else
				IntPtr f = IntPtr.Zero;
#endif
#endif
				do
				{
					// Next filter
#if DSHOWNET
					hr = enumMon.Next( 1, mon, f );
#else
#if VS2003
					hr = enumMon.Next( 1, mon, out f );
#else
					hr = enumMon.Next( 1, mon, f );
#endif
#endif
					if( (hr != 0) || (mon[0] == null) )
						break;
					
					// Add the filter
					Filter filter = new Filter( mon[0] );
					InnerList.Add( filter );

					// Release resources
					Marshal.ReleaseComObject( mon[0] );
					mon[0] = null;
				}
				while(true);

				// Sort
				InnerList.Sort();
			}
			finally
			{
				enumDev = null;
				if( mon[0] != null )
					Marshal.ReleaseComObject( mon[0] ); mon[0] = null;
				if( enumMon != null )
					Marshal.ReleaseComObject( enumMon ); enumMon = null;
				if( comObj != null )
					Marshal.ReleaseComObject( comObj ); comObj = null;
			}
		}
Ejemplo n.º 58
0
		public static object GetMSDEVFromGIT(string strProgID, string processId)		
		{			
			UCOMIRunningObjectTable prot;			
			UCOMIEnumMoniker pMonkEnum;			
			try			
			{				
				GetRunningObjectTable(0,out prot);				
				prot.EnumRunning(out pMonkEnum);				
				pMonkEnum.Reset();          // Churn through enumeration.				
				int fetched;				
				UCOMIMoniker []pmon = new UCOMIMoniker[1];				
				while(pMonkEnum.Next(1, pmon, out fetched) == 0) 				
				{					
					UCOMIBindCtx pCtx;					
					CreateBindCtx(0, out pCtx);					
					string str;					
					pmon[0].GetDisplayName(pCtx,null,out str);
//					#if DEBUG
//					System.Windows.Forms.MessageBox.Show(str+"   strProgId="+strProgID+"  processId="+processId);
//					#endif
					if(str.IndexOf(strProgID)>0 && (str.IndexOf(":"+processId)>0 || processId==""))
					{		
						object objReturnObject;		
						prot.GetObject(pmon[0],out objReturnObject);	
						object ide = (object)objReturnObject;		
						return ide;		
					}		
				}	
			}	
			catch	
			{	
				return null;	
			}
			return null;	
		}
Ejemplo n.º 59
0
		int MkParseDisplayName(
			UCOMIBindCtx pbc,
			string szUserName,
			ref int pchEaten,
			out UCOMIMoniker ppmk);
Ejemplo n.º 60
0
 protected string getName(UCOMIMoniker moniker)
 {
     object ppvObj = null;
     IPropertyBag bag = null;
     string str2;
     try
     {
         Guid gUID = typeof(IPropertyBag).GUID;
         moniker.BindToStorage(null, null, ref gUID, out ppvObj);
         bag = (IPropertyBag) ppvObj;
         object pVar = "";
         int errorCode = bag.Read("FriendlyName", ref pVar, IntPtr.Zero);
         if (errorCode != 0)
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
         string str = pVar as string;
         if ((str == null) || (str.Length < 1))
         {
             throw new NotImplementedException("Device FriendlyName");
         }
         str2 = str;
     }
     catch (Exception)
     {
         str2 = "";
     }
     finally
     {
         bag = null;
         if (ppvObj != null)
         {
             Marshal.ReleaseComObject(ppvObj);
         }
         ppvObj = null;
     }
     return str2;
 }