在Excel会话中首次调用Add-In 管理器时,调用此函数。此函数用于为Add-In管理器提供Add-In信息。
如果XLL中同时输出了这两个函数,Excel 2007会优先调用 xlAddInManagerInfo12 。在使用xlAddInManagerInfo12时,同xlAddInManagerInfo 一样,需要注意避免不同Excel版本中可能产生的不同效果。
它们之间的不同之处,xlAddInMangerInfo12 返回XLOPER12数据类型,然而xlAddInMangerInfo 返回 XLOPER 数据类型。这两个函数是对XLL来说可选函数。
声明
LPXLOPER WINAPI xlAddInManagerInfo(LPXLOPER pxAction);
LPXLOPER12 WINAPI xlAddInManagerInfo12(LPXLOPER12 pxAction);
参数
pxAction:XLOPER/XLOPER12 的数值型指针(xltypeInt 或 xltypeNum 类型)
属性值/返回值
如果 pxAction 值是1,那么你的这个函数实现,就可以返回关于add-in的字符串信息,例如add-in 名称和版本吧。否则返回 #VALUE!。如果你没有返回字符串,Excel会把它的返回值转换成字符串。
备注
如果返回的是一个动态分配的字符串内存指针,你必需确保它的缓存能可以正常释放。如果此内存空间由Excel进行分配。你就需要设置xlbitXLFree选项。如果字符串由DLL分配内存,你就需要设置为 xlbitDLLFree,,然后实现xlAutoFree或xlAutoFree12。
实例
LPXLOPER12 WINAPI xlAddInManagerInfo12(LPXLOPER12 xAction)
{
static XLOPER12 xInfo, xIntAction;
/*
** This code coerces the passed-in value to an integer. This is how the
** code determines what is being requested. If it receives a 1, it returns a
** string representing the long name. If it receives anything else, it
** returns a #VALUE! error.
*/
Excel12f(xlCoerce, &xIntAction, 2, xAction, TempInt12(xltypeInt));
if(xIntAction.val.w == 1)
{
xInfo.xltype = xltypeStr;
xInfo.val.str = L"\026Example Standalone DLL";
}
else
{
xInfo.xltype = xltypeErr;
xInfo.val.err = xlerrValue;
}
// Word of caution - returning static XLOPERs/XLOPER12s is not thread safe
// for UDFs declared as thread safe. Use alternate memory allocation mechanisms.
return (LPXLOPER12)&xInfo;
}