Example #1
0
        public static string GetCategoryName(Guid catid)
        {
            Guid   clsid = new Guid("{0002E005-0000-0000-C000-000000000046}");
            Guid   iid   = typeof(ICatInformation).GUID;
            IntPtr pCatMgr;
            string strDesc = catid.ToString("B");

            if (CoCreateInstance(ref clsid, IntPtr.Zero, CLSCTX.CLSCTX_INPROC_SERVER, ref iid, out pCatMgr) == 0)
            {
                ICatInformation catInfo = (ICatInformation)Marshal.GetObjectForIUnknown(pCatMgr);
                IntPtr          pStrDesc;

                try
                {
                    catInfo.GetCategoryDesc(ref catid, 0, out pStrDesc);
                    strDesc = Marshal.PtrToStringUni(pStrDesc);
                    Marshal.FreeCoTaskMem(pStrDesc);
                }
                catch (COMException ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                }

                Marshal.ReleaseComObject(catInfo);
                Marshal.Release(pCatMgr);
            }

            return(strDesc);
        }
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Free any other managed objects here.
                //
            }

            // Free any unmanaged objects here.
            //

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

            _disposed = true;
        }
Example #3
0
        /// <summary>
        /// Fetches the classes in the specified category.
        /// </summary>
        public static List <Guid> EnumClassesInCategory(Guid category)
        {
            ICatInformation manager = (ICatInformation)CreateInstance(CLSID_StdComponentCategoriesMgr);

            object unknown = null;

            try
            {
                manager.EnumClassesOfCategories(
                    1,
                    new Guid[] { category },
                    0,
                    null,
                    out unknown);

                OpcRcw.Comn.IEnumGUID enumerator = (OpcRcw.Comn.IEnumGUID)unknown;

                List <Guid> classes = new List <Guid>();

                Guid[] buffer = new Guid[10];

                while (true)
                {
                    int fetched = 0;
                    enumerator.Next(buffer.Length, buffer, out fetched);

                    if (fetched == 0)
                    {
                        break;
                    }

                    for (int ii = 0; ii < fetched; ii++)
                    {
                        classes.Add(buffer[ii]);
                    }
                }

                return(classes);
            }
            finally
            {
                ReleaseServer(unknown);
                ReleaseServer(manager);
            }
        }
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
                return;

            if (disposing)
            {
                // Free any other managed objects here.
                //
            }

            // Free any unmanaged objects here.
            //

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

            _disposed = true;
        }
Example #5
0
        // Gets the objects to iterate over to make the child nodes
        protected override ICollection GetChildren()
        {
            lock (_allClasses)
            {
                if (_allClasses.Count > 0)
                {
                    return(_allClasses.Values);
                }

                try
                {
                    IntPtr comObj;
                    int    result = NoGoop.Win32.ActiveX.CoCreateInstance
                                        (ref NoGoop.Win32.ActiveX.CategoriesMgrCLSID,
                                        (IntPtr)0,
                                        NoGoop.Win32.ActiveX.CLSCTX_INPROC_SERVER,
                                        ref NoGoop.Win32.ActiveX.IUnknownIID,
                                        out comObj);

                    TraceUtil.WriteLineInfo(this,
                                            "com create: 0x"
                                            + result.ToString("X")
                                            + " " + comObj);
                    if (result == 0)
                    {
                        ICatInformation catInfo = (ICatInformation)
                                                  Marshal.GetObjectForIUnknown(comObj);

                        // Get the CLSIDs associated with each category
                        Guid[] cats  = new Guid[1];
                        Guid[] cats1 = new Guid[0];
                        cats[0] = _catInfo._guid;
                        IEnumGUID enumClsIds;
                        catInfo.EnumClassesOfCategories(1,
                                                        cats,
                                                        0,
                                                        cats1,
                                                        out enumClsIds);

                        Guid clsId;
                        uint numRet;
                        while (true)
                        {
                            enumClsIds.Next(1, out clsId, out numRet);
                            if (numRet == 0)
                            {
                                break;
                            }

                            BasicInfo info = ComClassInfo.GetClassInfo(clsId);
                            if (info != null)
                            {
                                _allClasses.Add(info, info);
                            }
                        }

                        Marshal.ReleaseComObject(enumClsIds);
                        Marshal.ReleaseComObject(catInfo);
                    }
                }
                catch (Exception ex)
                {
                    TraceUtil.WriteLineIf(null, TraceLevel.Info,
                                          "Categories - failure to read: "
                                          + _catInfo._guid + " " + ex);
                }
                return(_allClasses.Values);
            }
        }
Example #6
0
        /// <summary>
        /// Fetches the classes in the specified categories.
        /// </summary>
        public static List <Guid> EnumClassesInCategories(params Guid[] categories)
        {
            ICatInformation manager = (ICatInformation)CreateLocalServer(CLSID_StdComponentCategoriesMgr);

            object unknown = null;

            try
            {
                manager.EnumClassesOfCategories(
                    1,
                    categories,
                    0,
                    null,
                    out unknown);

                IEnumGUID enumerator = (IEnumGUID)unknown;

                List <Guid> classes = new List <Guid>();

                Guid[] buffer = new Guid[10];

                while (true)
                {
                    int fetched = 0;

                    IntPtr pGuids = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * buffer.Length);

                    try
                    {
                        enumerator.Next(buffer.Length, pGuids, out fetched);

                        if (fetched == 0)
                        {
                            break;
                        }

                        IntPtr pos = pGuids;

                        for (int ii = 0; ii < fetched; ii++)
                        {
                            buffer[ii] = (Guid)Marshal.PtrToStructure(pos, typeof(Guid));
                            pos        = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        }
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(pGuids);
                    }

                    for (int ii = 0; ii < fetched; ii++)
                    {
                        classes.Add(buffer[ii]);
                    }
                }

                return(classes);
            }
            finally
            {
                ReleaseServer(unknown);
                ReleaseServer(manager);
            }
        }
        private bool _disposed; // Flag: Has Dispose already been called?

        public CategoryEnumerator(string host)
        {
            MaxItemsPerRequest = 16;
            _componentCategoriesMgr = Com.CreateInstance(typeof(StdComponentCategoriesMgr).GUID, host, null);
            _catInformation = (ICatInformation) _componentCategoriesMgr;
        }
        private bool _disposed; // Flag: Has Dispose already been called?

        public CategoryEnumerator(string host)
        {
            MaxItemsPerRequest      = 16;
            _componentCategoriesMgr = Com.CreateInstance(typeof(StdComponentCategoriesMgr).GUID, host, null);
            _catInformation         = (ICatInformation)_componentCategoriesMgr;
        }