如何从无法注册到函数向导的xll加载项调用函数? [英] How do I call a function from an xll add-in which could not be registered to the function wizard?

查看:163
本文介绍了如何从无法注册到函数向导的xll加载项调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xll(一个相当复杂的c ++项目)导出一个函数,由于历史原因,它需要大量的参数,精确的 20



这是一个神奇的数字:显然在Excel 2003中最多有30个参数(在Microsoft Office Excel 2003中, ),但超过20功能不能在功能向导中注册



现在,因为它发生了,你可以猜到,我被要求添加 3个参数。好的,所以参数计数增加到23(至少,这个函数不是为人类消费,但总是由VBA包装调用)。



用VC ++调试器附加到Excel进程,我在注册时获得错误代码4,它代表 xlretInvCount



我确认逗号分隔的参数名称的字符串是短于255个字符
Btw,我使用xlw 4(旧版本,我知道)。



因此,如果限制为30,我希望能够调用我的函数通过

  Application.Run(function name,.....参数列表非常长)

,但不使用向导。麻烦的是,VBA告诉我的功能没有注册。



那么,如何正确使用一个拥有超过20个参数并小于30的函数?



注意:请不要说明显而易见的。我知道问题的真正症结所在。目前不可能进行重构。

解决方案

由于你通过VBA调用你的函数,你可以直接调用它,甚至不需要注册它,即NOT USING XLW。 / p>


  • 在C / C ++中声明: externCint __declspec(dllexport)_stdcall myfunc(double arg1,double * arg2,...)

  • 在VBA中声明: Function MyFunc& LibC:\myL.dll别名_myfunc @ 1(ByVal arg1 As Double,ByRef arg2 As Double,...)



@ 1指的是.def文件中函数的位置。



现在你可以调用函数form VBA。请参阅 http://aandreasen.wordpress.com/2008/05/05/how-to-create-a-dll-for-ms-excel-vba-with-microsoft -visual-c-2008-command-line-tools /


I have an xll (a rather complex c++ project) exporting a function which, for historical reasons, takes a large number of arguments, and precisely 20.

This is a magic number: apparently in Excel 2003 there is a maximum number of 30 arguments (" In Microsoft Office Excel 2003, the maximum number of arguments that any function can take is 30, although most take fewer than this. "), but over 20 the function cannot be registered in the function wizard.

Now, as it happens and as you could guess, I have been required to add 3 more arguments. Ok, so the argument count goes up to 23 (at least, this function is not intended for "human consumption" but is always called by a VBA wrapper).

By attaching to the Excel process with VC++ debugger, I get at registration time an error code 4, which stands for xlretInvCount.

I have made sure that the string of comma separated argument names is shorter than 255 characters. Btw, I am using xlw 4 (old version, I know).

So, if the limit is 30 I expect to be able to invoke my function via

Application.Run("function name", ..... very long list of arguments) 

but not to use the wizard. Trouble is that VBA tells me that the function is not registered.

So, how do I properly use a function which takes more than 20 arguments and less than 30?

NB: please refrain from stating the obvious. I know where the real crux of the problem is. A refactoring is not possible at the moment.

解决方案

Since you call your function via VBA you might call it directly, not even registering it, i.e., NOT USING XLW.

  • Declare in C/C++: extern "C" int __declspec(dllexport) _stdcall myfunc(double arg1, double* arg2, ...)
  • Declare in VBA: Function MyFunc& Lib "C:\myL.dll" Alias "_myfunc@1" (ByVal arg1 As Double, ByRef arg2 As Double, ...)

The @1 refers to the position in of the function in the .def file.

Now you can call the function form VBA. See http://aandreasen.wordpress.com/2008/05/05/how-to-create-a-dll-for-ms-excel-vba-with-microsoft-visual-c-2008-command-line-tools/

这篇关于如何从无法注册到函数向导的xll加载项调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆