示例#1
0
        /// <summary>
        /// Creates COM class desciptions out of ComVisible CLR class type.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static ComClassInfo CreateClass(Type t)
        {
            raiseErrorOnBadClassType(t);
            var attrs = CustomAttributeData.GetCustomAttributes(t);

            if (!IsComVisible(attrs))
            {
                throw new ArgumentException("The CLR type must be COM visible.", "t");
            }

            var reg = new ComClassInfo();

            reg.Assembly = new AssemblyInfo(t.Assembly);
            reg.Class    = t.FullName;
            //TODO: optimize string usage for many calls of this
            CustomAttributeData progIdAttr = getCustomAttribute(attrs, typeof(ProgIdAttribute));

            reg.ProgId = progIdAttr != null?progIdAttr.ConstructorArguments.First().Value.ToString() : reg.Class;

            reg.ThreadingModel    = "Both";//NOTE: looks like this is default for .NET
            reg.Guid              = t.GUID.ToString("B").ToUpper();
            reg.RuntimeVersion    = t.Assembly.ImageRuntimeVersion;
            reg.RuntimeEntryPoint = "mscoree.dll";//TODO: change this depending on runtime version
            return(reg);
        }
示例#2
0
 protected static void unregisterInProcServer(RegistryKey classes, ComClassInfo reg)
 {
     using (classes)
     {
         using (RegistryKey clsidKey = classes.OpenSubKeyDeletion(CLSID))
         {
             if (clsidKey != null) //NOTE: to be safe if can happen clean machine without any user specific installation
             {
                 clsidKey.DeleteSubKeyTree(reg.Guid, false);
             }
         }
         classes.DeleteSubKeyTree(reg.ProgId, false);
     }
 }
示例#3
0
 protected static void registerInProcServer(RegistryKey classes, ComClassInfo reg)
 {
     using (classes)
     {
         using (RegistryKey clsidKey = classes.CreateSubKey(CLSID))
         {
             using (RegistryKey guidKey = clsidKey.CreateSubKey(reg.Guid))
             {
                 guidKey.SetValue("", reg.Class);
                 using (RegistryKey inprocServer32 = guidKey.CreateSubKey("InprocServer32"))
                 {
                     inprocServer32.SetValue("", reg.RuntimeEntryPoint);
                     inprocServer32.SetValue("ThreadingModel", reg.ThreadingModel);
                     inprocServer32.SetValue("Class", reg.Class);
                     inprocServer32.SetValue("RuntimeVersion", reg.RuntimeVersion);
                     inprocServer32.SetValue("Assembly", reg.Assembly.FullName);
                     using (RegistryKey version = inprocServer32.CreateSubKey(reg.Assembly.GetName().Version.ToString()))
                     {
                         version.SetValue("Class", reg.Class);
                         version.SetValue("Assembly", reg.Assembly.FullName);
                         version.SetValue("RuntimeVersion", reg.RuntimeVersion);
                     }
                 }
                 using (RegistryKey progIdKey = guidKey.CreateSubKey("ProgId"))
                 {
                     progIdKey.SetValue("", reg.ProgId);
                 }
                 using (RegistryKey categories = guidKey.CreateSubKey("Implemented Categories"))
                 {
                     using (categories.CreateSubKey("{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}"))
                     {
                     }
                 }
             }
         }
         using (RegistryKey prodIdKey = classes.CreateSubKey(reg.ProgId))
         {
             prodIdKey.SetValue("", reg.Class);
             using (RegistryKey prodIdToClassId = prodIdKey.CreateSubKey(CLSID))
             {
                 prodIdToClassId.SetValue("", reg.Guid);
             }
         }
     }
 }
示例#4
0
 protected static void registerInProcServer(RegistryKey classes, ComClassInfo reg)
 {
     using (classes)
     {
         using (RegistryKey clsidKey = classes.CreateSubKey(CLSID))
         {
             using (RegistryKey guidKey = clsidKey.CreateSubKey(reg.Guid))
             {
                 guidKey.SetValue("", reg.Class);
                 using (RegistryKey inprocServer32 = guidKey.CreateSubKey("InprocServer32"))
                 {
                     inprocServer32.SetValue("", reg.RuntimeEntryPoint);
                     inprocServer32.SetValue("ThreadingModel", reg.ThreadingModel);
                     inprocServer32.SetValue("Class", reg.Class);
                     inprocServer32.SetValue("RuntimeVersion", reg.RuntimeVersion);
                     inprocServer32.SetValue("Assembly", reg.Assembly.FullName);
                     using (RegistryKey version = inprocServer32.CreateSubKey(reg.Assembly.GetName().Version.ToString()))
                     {
                         version.SetValue("Class", reg.Class);
                         version.SetValue("Assembly", reg.Assembly.FullName);
                         version.SetValue("RuntimeVersion", reg.RuntimeVersion);
                     }
                 }
                 using (RegistryKey progIdKey = guidKey.CreateSubKey("ProgId"))
                 {
                     progIdKey.SetValue("", reg.ProgId);
                 }
                 using (RegistryKey categories = guidKey.CreateSubKey("Implemented Categories"))
                 {
                     using (categories.CreateSubKey("{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}"))
                     {
                     }
                 }
             }
         }
         using (RegistryKey prodIdKey = classes.CreateSubKey(reg.ProgId))
         {
             prodIdKey.SetValue("", reg.Class);
             using (RegistryKey prodIdToClassId = prodIdKey.CreateSubKey(CLSID))
             {
                 prodIdToClassId.SetValue("", reg.Guid);
             }
         }
     }
 }
        /// <summary>
        /// Creates COM class desciptions out of ComVisible CLR class type.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static ComClassInfo CreateClass(Type t)
        {
            raiseErrorOnBadClassType(t);
            var attrs = CustomAttributeData.GetCustomAttributes(t);
            if (!IsComVisible(attrs))
                throw new ArgumentException("The CLR type must be COM visible.", "t");

            var reg = new ComClassInfo();

            reg.Assembly = new AssemblyInfo(t.Assembly);
            reg.Class = t.FullName;
            //TODO: optimize string usage for many calls of this
            CustomAttributeData progIdAttr = getCustomAttribute(attrs, typeof(ProgIdAttribute));
            reg.ProgId = progIdAttr != null ? progIdAttr.ConstructorArguments.First().Value.ToString() : reg.Class;
            reg.ThreadingModel = "Both";//NOTE: looks like this is default for .NET
            reg.Guid = t.GUID.ToString("B").ToUpper();
            reg.RuntimeVersion = t.Assembly.ImageRuntimeVersion;
            reg.RuntimeEntryPoint = "mscoree.dll";//TODO: change this depending on runtime version
            return reg;
        }
示例#6
0
 protected static void unregisterInProcServer(RegistryKey classes, ComClassInfo reg)
 {
     using (classes)
     {
         using (RegistryKey clsidKey = classes.OpenSubKeyDeletion(CLSID))
         {
             if (clsidKey != null) //NOTE: to be safe if can happen clean machine without any user specific installation
                 clsidKey.DeleteSubKeyTree(reg.Guid, false);
         }
         classes.DeleteSubKeyTree(reg.ProgId, false);
     }
 }