Search code examples
c++visual-c++mfcc2664

C++ MFC error C2664


I'm trying to make a simple window using c++ and mfc. the following code is taken from the book "Visual C++ and MFC Fundamentals" but it doesn't work. I get error C2664:BOOL CFrameWnd::Create(LPCTSTR,LPCTSTR, ... ) cannot convert argument 2 from const char[20] to LPCTSTR. how can I change the code in order for it to work?

#include <afxwin.h>
class CSimpleFrame : public CFrameWnd
{
public:
CSimpleFrame()
{
// Create the window's frame
Create(NULL, "Windows Application");
}
};
struct CSimpleApp : public CWinApp
{
BOOL InitInstance()
{
// Use a pointer to the window's frame for the application
// to use the window
CSimpleFrame *Tester = new CSimpleFrame ();
m_pMainWnd = Tester;
// Show the window
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CSimpleApp theApp;

Solution

  • You are probably building your application with Unicode character set (which is the default setting). Change the offending line to:

    Create(NULL, _T("Windows Application"));
    

    Depending on character set, _T expands either to nothing (MBSC), or to L (Unicode) which results in wide character string.