Pregunta

The szTip field is 128 characters long, and unicode. It is of type TCHAR, which is typedef'd as WCHAR. So i have no clue why the following code snippet will not compile.

nid.szTip = _T("ToolTip");

The compile error is

error C2440: '=' : cannot convert from 'const wchar_t [8]' to 'WCHAR [128]'

Any advice?

¿Fue útil?

Solución

Your code would work if you were assigning to a TCHAR*. However, szTip is not a TCHAR*, it is declared as TCHAR szTip[64].

So you need to copy the contents of the string to the buffer. Like this:

_tcscpy(nid.szTip, _T("ToolTip"));

Do you really need to support both ANSI and Unicode builds? If not then stop using TCHAR and switch to Unicode. Then you could write a more readable version.

wcscpy(nid.szTip, L"ToolTip");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top