1

i just started learning MFC..found a tutorial here http://bit.ly/j2uhHO ..just tried the same thing in VS2010 but getting a compilation error in this code..

void CChildView::OnPaint() 
{

    CPaintDC dc(this); // device context for painting

    dc.TextOut(0, 0, "Hello, world!");

    // TODO: Add your message handler code here

    // Do not call CWnd::OnPaint() for painting messages
}

And the error is:

error C2664: 'BOOL CDC::TextOutW(int,int,const CString &)' : cannot convert parameter 3 from 'const char [14]' to 'const CString &'

Can anyone solve this and suggest some mfc tutorials please..thank u..

schnaader
  • 49,103
  • 10
  • 104
  • 136
harish
  • 328
  • 2
  • 5
  • 14

2 Answers2

3

The error tells you whats exactly wrong.

error C2664: 'BOOL CDC::TextOutW(int,int,const CString &)' : cannot convert parameter 3 from 'const char [14]' to 'const CString &'

TextOutW() is expecting const CString & as the third parameter and you are passing const char [14]

You need to do:

dc.TextOut(0, 0, L"Hello, world!");  

Which passes the third argument in the format desired by the function.

For MFC resources to refer, you see this.

Community
  • 1
  • 1
Alok Save
  • 202,538
  • 53
  • 430
  • 533
1

The problem is that Windows by default uses wide characters wchar_t for texts. You would need

    dc.TextOut(0, 0, L"Hello, world!"); 
Bo Persson
  • 90,663
  • 31
  • 146
  • 203