Exemplo n.º 1
0
        public static void RegisterFunction(Type type)
        {
            try
            {
                // add codebase entry
                Assembly    thisAssembly = Assembly.GetAssembly(typeof(Addin));
                RegistryKey key          = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\1.0.0.0");
                key.SetValue("CodeBase", thisAssembly.CodeBase);
                key.Close();

                Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable");

                // add bypass key
                // http://support.microsoft.com/kb/948461
                key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}");
                string defaultValue = key.GetValue("") as string;
                if (null == defaultValue)
                {
                    key.SetValue("", "Office .NET Framework Lockback Bypass Key");
                }
                key.Close();

                OfficeRegistry.CreateAddinKey("Excel", _progId, _addinFriendlyName, _addinDescription);
                OfficeRegistry.CreateAddinKey("Word", _progId, _addinFriendlyName, _addinDescription);
                OfficeRegistry.CreateAddinKey("Outlook", _progId, _addinFriendlyName, _addinDescription);
                OfficeRegistry.CreateAddinKey("PowerPoint", _progId, _addinFriendlyName, _addinDescription);
                OfficeRegistry.CreateAddinKey("Access", _progId, _addinFriendlyName, _addinDescription);
            }
            catch (Exception exception)
            {
                string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
                MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
 public string GetCustomUI(string RibbonID)
 {
     try
     {
         return(ReadTextFileFromRessource("RibbonUI.xml"));
     }
     catch (Exception exception)
     {
         OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in GetCustomUI. ", exception);
         return("");
     }
 }
Exemplo n.º 3
0
 public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
 {
     try
     {
         if (null != _application)
         {
             _application.Dispose();
         }
     }
     catch (Exception exception)
     {
         OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in OnDisconnection. ", exception);
     }
 }
Exemplo n.º 4
0
        public static void UnregisterFunction(Type type)
        {
            try
            {
                Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable", false);

                OfficeRegistry.DeleteAddinKey(OfficeRegistry.Excel + _progId);
                OfficeRegistry.DeleteAddinKey(OfficeRegistry.Word + _progId);
                OfficeRegistry.DeleteAddinKey(OfficeRegistry.Outlook + _progId);
                OfficeRegistry.DeleteAddinKey(OfficeRegistry.PowerPoint + _progId);
                OfficeRegistry.DeleteAddinKey(OfficeRegistry.Access + _progId);
            }
            catch (Exception exception)
            {
                string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
                MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                _application = Core.Default.CreateObjectFromComProxy(null, Application);

                /*
                 * _application is stored as COMObject the common base type for all reference types in NetOffice
                 * because this addin is loaded in different office application.
                 *
                 * with the CreateObjectFromComProxy method the _application instance is created as corresponding wrapper based on the com proxy type
                 */

                if (_application is Excel.Application)
                {
                    _hostApplicationName = "Excel";
                }
                else if (_application is Word.Application)
                {
                    _hostApplicationName = "Word";
                }
                else if (_application is Outlook.Application)
                {
                    _hostApplicationName = "Outlook";
                }
                else if (_application is PowerPoint.Application)
                {
                    _hostApplicationName = "PowerPoint";
                }
                else if (_application is Access.Application)
                {
                    _hostApplicationName = "Access";
                }
            }
            catch (Exception exception)
            {
                if (_hostApplicationName != null)
                {
                    OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in OnConnection. ", exception);
                }
            }
        }