C++ 用ATL 7.0字符串转换类和宏替换T2OLE

C++ 用ATL 7.0字符串转换类和宏替换T2OLE,c++,visual-c++,atl,ole,C++,Visual C++,Atl,Ole,根据,在循环中使用T2OLE可能会导致堆栈溢出,我的应用程序在循环内的代码中使用T2OLE进行字符串转换。我发现使用字符串转换类和宏有很多好处,它还解决了堆栈溢出问题 我尝试使用ATL 7.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 Callso

根据,在循环中使用T2OLE可能会导致堆栈溢出,我的应用程序在循环内的代码中使用T2OLE进行字符串转换。我发现使用字符串转换类和宏有很多好处,它还解决了堆栈溢出问题

我尝试使用ATL 7.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)
{
....
}
同样的,我还有另外一个地方,在那里它会发出cstring到_bstr\t,当我在那里替换时,我得到了这个

 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和helper CA2W类之间可能缺少转换,您需要通过提供转换来提供帮助

_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));
_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));