/// <summary> /// Registers a managed type that's exposed for COM interop as safe for initializing and scripting /// </summary> /// <param name="comType"></param> public static void RegisterSafeForScripting(Type comType) { Guid clsid = comType.GUID; Guid interfaceSafeScripting = new Guid(CATID_SafeForScripting); Guid interfaceSafeForInitializing = new Guid(CATID_SafeForInitializing); ICatRegister reg = (ICatRegister) new ComComponentCategoriesManager(); reg.RegisterClassImplCategories(ref clsid, 1, new Guid[] { interfaceSafeScripting }); reg.RegisterClassImplCategories(ref clsid, 1, new Guid[] { interfaceSafeForInitializing }); }
/// <summary> /// Registers the classes in the specified category. /// </summary> public static void RegisterClassInCategory(Guid clsid, Guid catid, string description) { ICatRegister manager = (ICatRegister)CreateLocalServer(CLSID_StdComponentCategoriesMgr); try { string existingDescription = null; try { ((ICatInformation)manager).GetCategoryDesc(catid, 0, out existingDescription); } catch (Exception e) { existingDescription = description; if (String.IsNullOrEmpty(existingDescription)) { if (catid == CATID_OPCDAServer20) { existingDescription = CATID_OPCDAServer20_Description; } else if (catid == CATID_OPCDAServer30) { existingDescription = CATID_OPCDAServer30_Description; } else if (catid == CATID_OPCAEServer10) { existingDescription = CATID_OPCAEServer10_Description; } else if (catid == CATID_OPCHDAServer10) { existingDescription = CATID_OPCHDAServer10_Description; } else { throw new ApplicationException("No description for category available", e); } } CATEGORYINFO info; info.catid = catid; info.lcid = 0; info.szDescription = existingDescription; // register category. manager.RegisterCategories(1, new CATEGORYINFO[] { info }); } // register class in category. manager.RegisterClassImplCategories(clsid, 1, new Guid[] { catid }); } finally { ReleaseServer(manager); } }
/// <summary> /// Registers the classes in the specified category. /// </summary> public static void RegisterClassInCategory(Guid clsid, Guid catid, string description) { ICatRegister manager = (ICatRegister)CreateInstance(CLSID_StdComponentCategoriesMgr); try { string exsistingDescription = null; try { ((ICatInformation)manager).GetCategoryDesc(catid, 0, out exsistingDescription); } catch (Exception e) { exsistingDescription = description; if (String.IsNullOrEmpty(exsistingDescription)) { if (catid == typeof(OpcRcw.Da.CATID_OPCDAServer30).GUID) { exsistingDescription = OpcRcw.Da.Constants.OPC_CATEGORY_DESCRIPTION_DA30; } if (catid == typeof(OpcRcw.Da.CATID_OPCDAServer20).GUID) { exsistingDescription = OpcRcw.Da.Constants.OPC_CATEGORY_DESCRIPTION_DA20; } else { throw new ApplicationException("No description for category available", e); } } CATEGORYINFO info; info.catid = catid; info.lcid = 0; info.szDescription = exsistingDescription; // register category. manager.RegisterCategories(1, new CATEGORYINFO[] { info }); } // register class in category. manager.RegisterClassImplCategories(clsid, 1, new Guid[] { catid }); } finally { ReleaseServer(manager); } }
public void RegisterCategories(Guid[] categoryIds) { _catRegister.RegisterClassImplCategories(ref _classId, (uint)categoryIds.Length, categoryIds); }