'xloper12 variable xltype = str using wide characters
I am trying to register some functions and have success up until the length of my string exceeds 255. I have written the below function to cycle through the list of parameters and convert the L"xxparametersxx". For any string <255 characters it works fine but when I get to the 256 character string it does not enter the corresponding code for the # of characters in the first entry. Would anyone have any ideas here please?
Joe
Function Code:
XLOPER12 CreateXLOPER12FromWStr(LPCWSTR cInput)
XLOPER12 lpx;
size_t len;
len = wcslen(cInput); wchar_t* lps = (wchar_t *)malloc((len + 2) * sizeof(wchar_t));
lps[0] = (wchar_t)(len+2);
wmemcpy_s(lps + 1, len, cInput, len); lpx.xltype = xltypeStr; lpx.val.str = lps;
return lpx;
Solution 1:[1]
Your function above appears valid (except missing braces!) and I can run it, although I'm not sure why you put len+2 into lps[0]: just the string length is sufficient. You may be hitting other limitations downstream, if you are using xlfRegister:
- The total length of comma-separated parameter names must be < 256 chars
- Help strings must be < 256 chars
- Function name must be < 256 chars
This is despite the XLOPER12 type allowing for considerably longer strings.
I don't recommend that anyone else use the C API directly: rather use my library xlOil which hides implementation details like the above and adds COM, GUI & RTD support. Or use Keith's xlladdins.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | stevecu |
