我已经创建了一个XLL+用户定义函数sum1,添加此加载项后,它可以在Excel中顺利运行。但是现在我正在构建另一个XLL,比如sum2。我希望我可以在这个插件sum2中调用sum1。由于sum1和sum2位于不同的XLL中,因此不能直接调用它们,需要一些代码才能实现。以前有没有人遇到过这个问题,有什么好的解决方法吗?
我在谷歌上搜索了这个问题,找到了下面的代码,这是由evaluate和UDF函数完成的。但是看起来代码很旧,适用于visual studio 2005,但不适用于2012,并且我在运行它时会得到#Name错误。
如果有人能帮我的话我会很感激的。非常感谢。
// Function: CalDaysInYear2
// Purpose: Calls a function in another XLL
//{{XLP_SRC(CalDaysInYear2)
// NOTE - the FunctionWizard will add and remove mapping code here.
// DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(CalDaysInYear2, "RI", "CalDaysInYear2",
"DayCount", "Date & Time", "Calls a function in another XLL,"
" which returns number of days in a year according to the"
" day count", "Day count convention\000", "\0appscope=1\0",
1)
extern "C" __declspec( dllexport )
LPXLOPER CalDaysInYear2(short DayCount)
{
XLL_FIX_STATE;
CXlOper xloResult;
//}}XLP_SRC
static int xlfEvaluate = 257;
static int xlUDF = 255;
CXlOper xloName, xloRef;
int rc = 0;
xloName = "CalDaysInYear";`enter code here`
if (!rc)
rc = xloRef.Excel(xlfEvaluate, 1, &xloName);
if (!rc)
rc = xloResult.Excel(xlUDF, 2, &xloRef, &CXlOper(DayCount, 0));
return xloResult.Ret();
}发布于 2014-02-03 13:32:40
要注意的第一个要点是,XLL是一个。
在构建XLL(DLL)时,Visual studio还应该创建一个具有相同基名的LIB文件(例如,如果第一个文件名为project1.XLL,那么它也应该创建project1.LIB)。
如果你将一个带有适当函数定义的头文件添加到你的第二个项目中,并将第一个项目创建的库添加到你的第二个项目中,那么VS应该注意调用GetProcAddress()等的麻烦。
extern "C" __declspec( dllimport )
LPXLOPER CalDaysInYear2(short DayCount);注意,第二个项目的头文件使用的是dllimport而不是dllexport。
https://stackoverflow.com/questions/20636037
复制相似问题