none
How to register an Excel Addin COM to be used by x64 Microsft Excel RRS feed

  • Question

  • Hi all,

    I am struggling to make a C# COM Addin visible for x64 Microstf Excel (2019). Until now my Addin is visible only for x86 Microsoft Excel, and never for the Microsoft Excel x64. 

    My Addin (Class Library) is compiled to AnyCPU, and is very basic, i have created only one class, with one function, no complex Dlls are referenced, i just need it to be visible for the moment.

    I am using the code below for COM Registration:

    ------------------------------------------------------------------------------

            [ComRegisterFunctionAttribute]
            public static void RegisterFunction(Type type)
            {
                Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type));
            }

            [ComUnregisterFunctionAttribute]
            public static void UnregisterFunction(Type type)
            {
                Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type), false);
            }

            private static string GetSubKeyName(Type type)
            {
                string s = @"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";

                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" +
                                    type.GUID.ToString().ToUpper() + "}\\InprocServer32");

                if (key != null)
                {
                    key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) +
                                     @"\mscoree.dll");
                }

                return s;
            }

    ---------------------------------------------------------------------

    The code above works perfectly for x86 Excel.

    After doing my researchs, i understood that the COM Addin should be registered in the x64 Regitry to be visible for x64 Excel, i used the following lines to do that but nothing worked:

    ---------------------------------------------------------------------

            // Version 1 : Registration to "Excel\\Addins" path

            [ComRegisterFunction()]
            private static void ComRegister(Type type)
            {
                string keyPath = "Software\\Microsoft\\Office\\Excel\\AddIns\\{" + type.GUID.ToString().ToUpper() + "}";
                RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                RegistryKey key = baseKey.CreateSubKey(keyPath);
                if (key != null)
                    key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + @"\mscoree.dll");
            }

            // Version 2 : Restration to "Wow6432Node"

            [ComRegisterFunction]
            public static void RegisterFunction(Type type)
            {
                string s = @"Wow6432Node\\CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";

                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("Wow6432Node\\CLSID\\{" +
                                                                                                    type.GUID.ToString().ToUpper() + "}\\InprocServer32");

                if (key != null)
                {
                    key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) +
                                     @"\mscoree.dll");
                }
                Registry.ClassesRoot.CreateSubKey(s);
            }

    -----------------------------------------------------------------------------

    Can anyone help me make this very basic Addin work for x64 Excel ?

    Thank you in advance

    Wednesday, February 19, 2020 2:09 PM