开发者

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 co开发者_如何学运维de 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..


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜