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?

有帮助吗?

解决方案

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");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top