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;
Your function above appears valid (except missing braces!) and I can run it, although I'm not sure why you put
len+2intolps[0]: just the string length is sufficient. You may be hitting other limitations downstream, if you are usingxlfRegister:This is despite the
XLOPER12type 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.