I have a slightly odd (though not terminal) issue when registering my XLL functions. I use the xlfRegister call, with the list of arguments as per usual, but have two issues:
Has anyone else encountered this? I am concerned that something unintended is happening when I construct the temporary byte-counted strings. This is not a big issue now, it could have some unintended consequences later if it turns out I am not passing strings correctly. I am using 64-bit Excel, and compiling a 64-bit xll (with the /D "_MBCS" compiler flag). I am using the Excel4v() calls under the hood with with LPXLOPER, and not Excel12v with LPXLOPER12s.
This is my registration call:
Excel(xlfRegister, 0, 15, pDll,TempStr2("myUDF"),
TempStr2("PCCPPP"),
TempStr2("myUDF"),
TempStr2("Param1,Param2,Param3,Param4,Param5"),
TempStr2("1"),
TempStr2("My UDF functions"),
TempStr2(""),
TempStr2(""),
TempStr2("Returns a secret"),
TempStr2("Function Parameter 1"),
TempStr2("Function Parameter 2"),
TempStr2("Function Parameter 3"),
TempStr2("Function Parameter 4"),
TempStr2("Function Parameter 5"));
With the TempStr2 function (taken from the amended framewrk.cpp from the SDK) implemented as:
LPXLOPER TempStr2(LPSTR lpstr)
{
LPXLOPER lpx;
lpx = (LPXLOPER)GetTempMemory(sizeof(XLOPER));
int len = __min(255, lstrlen(lpstr));
lpx->xltype = xltypeStr;
lpx->val.str = GetTempMemory(len + 1);
strncpy(lpx->val.str + 1, lpstr, len);
lpx->val.str[0] = (BYTE)len;
return lpx;
}
The UDF works fine, but being pedantic, this is what appears in the Function Wizard:
The first four parameter strings have a full stop (.) appended which was not in the original string. No great hardship (it might be by design ... if I put my own full-stop on the strings, a 2nd one does not appear). If I look at other functions in the Wizard, all the parameter help strings seem to end in a full-stop, so perhaps this is intentional.
The final string "Function Parameter 5", has lost the last character ('5') and has not been afforded the dignity of the extra full-stop, which suggests I may be losing two characters.
I'd be interested to hear any suggestions about what might be going on?
Aha ... I found this in the list of known SDK issues:
“Argument Description String Truncation in the Function Wizard
The pxArgumentHelp1 parameter and all subsequent parameters of the xlfRegister function are optional strings that correspond to the arguments of the XLL function. The Function Wizard displays these to provide help in the argument construction dialog box. Sometimes Excel truncates the string that corresponds to the final argument by one or two characters when displaying it in the dialog box. You can avoid this by adding an additional "empty string" as the last "argument help" parameter of your function registration.”
So, I will move on.