Pergunta

According to MSDN, using T2OLE in a loop may lead to stack overflow, my application uses T2OLE lot of places in the code inside loop for string conversion. I found that using ATL 7.0 string conversion classes and macros has lot of benefits and it solves the stack overflow issue as well,

I tried using the ATL 7.0 as below,

_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)
{
....
}

I found that CT2OLE in ATL 7.0 is equivalent to T2OLE but when I replaced T2OLE with CT2OLE I am getting this issue

Error: No suitable user defined conversion from "ATL:CA2W" to Cstring exists 

In the same way I have an other place where it does cstring to _bstr_t and when i replace over there I am getting this

 Error: No suitable user defined conversion from "ATL:CA2W" to _bstr_t exists 

Can any one help me with this issue?

Foi útil?

Solução

_bstr_t example("Hello world");
void Callsomemethod(CString y);
Callsomemethod(T2OLE(example)); //This is where I need to replace T2OLE

CString assumes you are passing TCHAR* compatible argument, whereas x2OLE macro gives you WCHAR* - you are using opposite direction conversion macro. And there might be missing conversion between CString and helper CA2W classes, where you need to help by providing a cast.

_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));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top