用ATL 7.0字符串转换类和宏替换T2OLE
Replacing T2OLE with a ATL 7.0 String conversion classes and Macros
根据MSDN的说法,在循环中使用T2OLE可能会导致堆栈溢出,我的应用程序在循环内的代码中使用了很多T2OLE来进行字符串转换。我发现使用ATL7.0字符串转换类和宏有很多好处,它还解决了堆栈溢出问题,
我试着使用ATL7.0如下,
_bstr_T example("Hello world");
for(i=o; i<10000; i++)
{
Callsomemethod(i,T2OLE(example)); //This is where I need to replace T2OLE
}
void Callsomemethod(int k, cstring y)
{
....
}
我发现ATL 7.0中的CT2OLE相当于T2OLE,但当我用CT2OLE替换T2OLE时,我得到了这个问题
Error: No suitable user defined conversion from "ATL:CA2W" to Cstring exists
以同样的方式,我有另一个地方,它对_bstr_t进行cstring,当我在那里替换时,我得到了这个
Error: No suitable user defined conversion from "ATL:CA2W" to _bstr_t exists
有人能帮我解决这个问题吗?
_bstr_t example("Hello world");
void Callsomemethod(CString y);
Callsomemethod(T2OLE(example)); //This is where I need to replace T2OLE
CString假设您传递的是与TCHAR*
兼容的参数,而x2OLE
宏提供的是WCHAR*
——您使用的是反向转换宏。并且CString
和helperCA2W
类之间可能缺少转换,您需要通过提供强制转换来提供帮助。
_bstr_t example("Hello world");
void Callsomemethod(CString y);
//void Callsomemethod(LPCTSTR y);
Callsomemethod(CString(example));
Callsomemethod(CString((BSTR) example));
Callsomemethod(OLE2CT(example));
Callsomemethod((LPCTSTR) OLE2CT(example));
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 如何用转义符替换字符串中的所有特殊字符
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 在一个读写器队列中,我可以用volatile替换原子吗
- 用符号版本替换对函数的所有调用
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 按平均值替换数组中的元素
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 初始化 std::vector 替换为单大括号而不是双大括号
- 删除/替换C++字符串中的多字符 (ÿû)
- 将 malloc 替换为数组
- 如何替换此示例代码片段中已弃用的handler_type_t或 boost::asio::handler_type?
- 如何在C++中用'\'替换''来处理转义序列?
- 替换密码:哪一个?
- 替换 C++17 中移除的绑定 1st
- 将 Boost MPL 容器替换为 C++17 功能
- C++:如何用单个命令替换复杂的迭代?
- 用ATL 7.0字符串转换类和宏替换T2OLE