Search code examples
c++visual-studio-2010mfccompiler-errorsvisual-c++-2010

Getting a compilation error in VS2010 by following the first hello world example


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..


Solution

  • 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.