Question

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;
Was it helpful?

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.

OTHER TIPS

If character set doesn't really matter to you and want to get rid of this kind of errors "forever", you could go to Project Properties -> Configuration Properties -> General -> Character Set, and set it to Use Multi-Byte Character Set. If not, _T() and/or L are your friends (depending on your character set settings)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top