RegisterMethods In EXCEL2003 error

Nov 5, 2012 at 9:41 AM

Hi,

some code like this:

  MethodInfo[] ff = typeof(Gildata.EXCEL.FuncAnalyse.FuncDeclare).GetMethods(BindingFlags.Static | BindingFlags.Public);


            List<MethodInfo> ms = new List<MethodInfo>();
            for (int i = 0; i < ff.Length; i++)
            {
                ms.Add(ff[i]);
            }

            ExcelDna.Integration.ExcelIntegration.RegisterMethods(ms);

 

It's do fine in Excel2007,but in Excel2003 it will be breakdown.

In fact ,I has alter Dna Source Code Order use more then 1000 funtions.

I declare more then 3000 functions in my Gildata.EXCEL.FuncAnalyse.FuncDeclare Class.

I think it's a bug in Excel4v method.

 

 

Coordinator
Nov 5, 2012 at 9:49 AM

Hi,

You are right that Excel-DNA only supports 1000 functions per add-in, but you can make a custom version that supports more.

One reason your registration might fail is if your functions have too many parameters. Under Excel 2003, a function can have at most 30 arguments, while the limit is 255 arguments under Excel 2007.

If this is not the reason for the problem, please make a small example that shows the problem, and I will be happy to take a closer look.

-Govert

Nov 5, 2012 at 10:33 AM

Hi,

My Step One by One:

1.Use DNA Source Code 0.30

2.ExcelDna.h

// EXPORT_COUNT defines the size of the thunk table.
// Must match the number of functions exported in ExcelDna.cpp and JmpExports64.asm
//#define EXPORT_COUNT 250
#define EXPORT_COUNT 6000

3.ExcelDna.cpp

// Declare the functions -- NOTE: list here must go from 0 to EXPORT_COUNT-1
expf(0)

expf(1)

...

expf(5999)

Rebuild Project ,I will get ExcelDna.xll (532 KB)

4.In My Vs2008,New Project as ClassLibery,Named DnaAddIn1 (.net 2.0)

5.Add New Class ,Named Test.cs

 public class Test
    {

 private static int i;

        public static int jishuqi()
        {
            i++;
            return i;
        }
        public static object jishuqi0()
        { return jishuqi(); }
        public static object jishuqi1()
        { return jishuqi(); }

....

 public static object jishuqi5000()
{ return jishuqi(); }

}

 

6.New

using System.Collections.Generic;
using ExcelDna.Integration;
using System.Reflection;
using System.Diagnostics;

   public class MyAddIn : IExcelAddIn
    {

  public void AutoOpen()
        {
            ExcelAsyncUtil.Initialize();
            ExcelIntegration.RegisterUnhandledExceptionHandler(
                delegate(object x)
                {
                    return null;
                });

            MethodInfo[] ff = typeof(Test).GetMethods(BindingFlags.Static | BindingFlags.Public);

            List<MethodInfo> ms = new List<MethodInfo>();
            ms.AddRange(ff);

            Stopwatch sp = new Stopwatch();
            sp.Start();
            ExcelDna.Integration.ExcelIntegration.RegisterMethods(ms);
            sp.Stop();
            Debug.WriteLine(sp.ElapsedMilliseconds);
        }

        public void AutoClose()
        {
        }

    }

7.It's Run in Excel2007 will be ok,but Excel2003 fail

 

Coordinator
Nov 5, 2012 at 10:50 AM

OK,

Is everything fine under Excel 2003 if you register a smaller number, say only 200 methods, or 1200 methods. Do you know what the limit is?

-Govert

Coordinator
Nov 5, 2012 at 9:53 PM

Hi,

OK, I've tried to recreate the problem in Excel 2002 using your details, but everything works as expected. I don't have easy access to an Excel 2003 installation. I noted that I had to add an ExplicitExports="true" attribute in the .dna file to prevent the functions from being registered automatically.

Can you describe what happens in the following cases?

* When you just have the functions public, and not registered by calling ExcelIntegration.RegisterMethods. (Removing the ExplicitExports="true" in the .dna file.)

* When you have fewer functions, but register them with ExcelIntegration.RegisterMethods. (Adding the ExplicitExports="true" in the .dna file again.) Is there a cut-off number where it works or fails?

In what I've tried so far, I could not recreate a problem with either way of registering - I had the 5000 different functions available on the sheet with no problems.

If you're able to check again and still have the problem, I suggest you mail me the project so that I can have a closer look.

-Govert

 

Nov 8, 2012 at 12:08 AM

Hi,

I removed function attribute [ExcelFunction(Description="测试方法")] in my Function Declare,I find it Will be Load Ok in Excel2003.

thanks