Hi Guys I wrore a simple VC "single document" interface program with MS VS_2005 when i wrote the following code Code: [COLOR=Red]void CFirstView::OnDraw(CDC* pDC) { CFirstDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; [COLOR=Blue] CString hello_string="Hi This is my 1st Document View";[/COLOR] // TODO: add draw code for native data here [COLOR=Blue]pDC->TextOutW(0,0,hello_string,hello_string.GetLength());[/COLOR] }[/COLOR] and copiled my program i get the error message below Code: [COLOR=DarkOrange]c:\documents and settings\falcon eyes\my documents\visual studio 2005\projects\first\first\firstview.cpp(54) :error C2440:'initializing' : cannot convert from 'const char [32]' to 'ATL::CStringT<BaseType,StringTraits>' 1>with 1>[ 1>BaseType=wchar_t, 1>StringTraits=StrTraitMFC_DLL<wchar_t> 1>] 1>Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit' 1>with 1>[ 1>BaseType=wchar_t, 1>StringTraits=StrTraitMFC_DLL<wchar_t>[/COLOR] does any one know why i'm getting an error message and what's the solution
You need to be providing the TCHAR There are 2 way to get out of it. 1. Have the hello_string declared as TCHAR array 2. Instead of passing the CString use the GetBuffer function to have the char array and then after the function returns use the ReleaseBuffer.
Hi shabbir 1st thanks for ur reply 2nd could u please give me more details what u mean by TCHAR array if u have any document about that or any usefull websites link and how can i declare my string as TCHAR array alsow could u pls write the code for how to pass a string using the GetBuffer Forgiveme i'm still learning how to program
TCHAR is nothing but declaring char array. Something Like TCHAR *str ="Your string"; or even TCHAR str[] ="Your String"; For GetBuffer it should be something like Code: CString hello_string="Hi This is my 1st Document View"; pDC->TextOutW(0,0,hello_string.GetBuffer(),hello_string.GetLength() ); hello_string.ReleaseBuffer(); I thought I was clear enough with the above post and so not gave any example.
Pls shabbir when i wrote the code TCHAR hello_string="Hi This is my 1st Document View"; // TODO: add draw code for native data here pDC->TextOutW(0,0,hello_string,32); I got this error message error C2440: 'initializing' : cannot convert from 'const char [32]' to 'TCHAR' is there's some wrong i did
Try making the TCHAR const or as of now you can go for something like const char as well because you dont need to confuse what is T there.
I changed the properties of my project as below General -> charcter set -> not set and i used TextOutA function and it works although there's warnning message Thanks