Click here to Skip to main content
15,886,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to set an integer value returned by a function to one edit control. and I tried it in the following ways.

C++
CString str;
Int res = 2;
Str.Format("%d", res);
m_conrol.SetWeindowTextw(str);

or
C++
CString str;
Int res = 2;
Str.Format(_T("%d"), res);
m_conrol.SetWeindowTextw(str);

But I am getting an error like this
Quote:
.error C2664: 'CWnd::SetWindowTextW' : cannot convert parameter 1 from 'char [17]' to 'LPCTSTR

How can I correct this?
Anybody please help.
Posted
Updated 29-May-14 22:00pm
v2
Comments
CHill60 30-May-14 4:10am    
Can you try LPCTSTR lpctSWT = str;
m_conrol.SetWindowTextW(lpctSWT);
and see if that works

1 solution

Don't use SetWindowTextW, since the rest of your code is MBCS/Unicode switchable. Use the base SetWindowText (without the W) and let the compiler generate the correct version. So your code should be:
C++
CString str;
Int res = 2;
Str.Format(_T("%d"), res);
m_conrol.SetWindowText(str);

Note also the use of the _T() macro, you should use it for all string constants.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900