Ejemplo n.º 1
0
        static void RegisterXlMethod(XlMethodInfo mi)
        {
            int index = registeredMethods.Count;

            XlAddIn.SetJump(index, mi.FunctionPointer);
            string exportedProcName = string.Format("f{0}", index);

            object[] registerParameters = GetRegisterParameters(mi, exportedProcName);
            string   registerName       = (string)registerParameters[3];

            if (!registeredNames.Add(registerName))
            {
                // Not added to the set of names, so it was already present
                // This function will be registered with a name that has already been used (by this add-in)
                if (mi.SuppressOverwriteError)
                {
                    // Logged at Info level - to allow re-registration without error popup
                    Logger.Registration.Info("Repeated function name: '{0}' - previous registration will be overwritten. ", registerName);
                }
                else
                {
                    // This logged as an error, but the registration continues - the last function with the name wins, for backward compatibility.
                    Logger.Registration.Error("Repeated function name: '{0}' - previous registration will be overwritten. ", registerName);
                }
            }

            // Basically suppress problems here !?
            try
            {
                object xlCallResult;
                XlCallImpl.TryExcelImpl(XlCallImpl.xlfRegister, out xlCallResult, registerParameters);
                Logger.Registration.Info("Register - XllPath={0}, ProcName={1}, FunctionType={2}, Name={3} - Result={4}",
                                         registerParameters[0], registerParameters[1], registerParameters[2], registerName,
                                         xlCallResult);
                if (xlCallResult is double)
                {
                    mi.RegisterId = (double)xlCallResult;
                    registeredMethods.Add(mi);
                    if (mi.IsCommand)
                    {
                        RegisterMenu(mi);
                        RegisterShortCut(mi);
                    }
                }
                else
                {
                    Logger.Registration.Error("xlfRegister call failed for function or command: '{0}'", mi.Name);
                }
                // Now clear out the xll path and store the parameters to support RegistrationInfo access.
                registerParameters[0] = null;
                registrationInfo.Add(registerParameters);
            }
            catch (Exception e)
            {
                Logger.Registration.Error(e, "Registration failed for function or command: '{0}'", mi.Name);
            }
        }
Ejemplo n.º 2
0
        private static void RegisterXlMethod(XlMethodInfo mi)
        {
            int index = registeredMethods.Count;

            XlAddIn.SetJump(index, mi.FunctionPointer);
            String exportedProcName = String.Format("f{0}", index);

            object[] registerParameters = GetRegisterParameters(mi, exportedProcName);
            if (!mi.IsCommand && !mi.IsHidden)
            {
                RecordFunctionInfo(registerParameters);
            }

            // Basically suppress problems here !?
            try
            {
                object xlCallResult;
                XlCallImpl.TryExcelImpl(XlCallImpl.xlfRegister, out xlCallResult, registerParameters);
                Debug.Print("Register - XllPath={0}, ProcName={1}, FunctionType={2}, MethodName={3} - Result={4}",
                            registerParameters[0], registerParameters[1], registerParameters[2], registerParameters[3],
                            xlCallResult);
                if (xlCallResult is double)
                {
                    mi.RegisterId = (double)xlCallResult;
                    registeredMethods.Add(mi);
                    if (mi.IsCommand)
                    {
                        RegisterMenu(mi);
                        RegisterShortCut(mi);
                    }
                }
                else
                {
                    // TODO: What to do here? LogDisplay??
                    Debug.Print("Registration Error! - Register call failed for method {0}", mi.Name);
                }
            }
            catch (Exception e)
            {
                // TODO: What to do here? LogDisplay??
                Debug.WriteLine("Registration Error! - " + e.Message);
            }
        }
Ejemplo n.º 3
0
 public byte[] GetResourceBytes(string resourceName, int type)
 => XlAddIn.GetResourceBytes(resourceName, type);
Ejemplo n.º 4
0
 public int LPenHelper(int wCode, ref XlCall.FmlaInfo fmlaInfo) => XlAddIn.LPenHelper(wCode, ref fmlaInfo);
Ejemplo n.º 5
0
 public Assembly LoadFromAssemblyBytes(byte[] assemblyBytes, byte[] pdbBytes)
 => XlAddIn.LoadAssemblyFromBytes(assemblyBytes, pdbBytes);
Ejemplo n.º 6
0
 public Assembly LoadFromAssemblyPath(string assemblyPath)
 => XlAddIn.LoadAssemblyFromPath(assemblyPath);