xloper12变量xltype = str使用宽字符
我试图注册一些功能并取得成功,直到字符串的长度超过255。我已经写了以下功能来循环浏览参数列表并转换L“ xxparametersxx”。对于任何字符串< 255个字符,它可以正常工作,但是当我到达256个字符串时,它不会输入第一个条目中字符#的相应代码。有人在这里有任何想法吗?
Joe
功能代码:
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您上面的功能看起来有效(除了缺少括号!),我可以运行它,尽管我不确定为什么您将
len+2
放入lps [0]
:只有弦长就足够了。如果您使用的是xlfregister
:尽管
Xloper12
类型允许允许更长的字符串。我不建议其他人直接使用C API:而是使用我的库xloil 详细信息如上所述,并添加了com,gui&amp; RTD支持。或使用 keith的Xlladdins 。
Your function above appears valid (except missing braces!) and I can run it, although I'm not sure why you put
len+2
intolps[0]
: just the string length is sufficient. You may be hitting other limitations downstream, if you are usingxlfRegister
: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.