【问题标题】:C++ MFC error C2664C++ MFC 错误 C2664
【发布时间】:2014-06-29 02:55:41
【问题描述】:

我正在尝试使用 c++ 和 mfc 制作一个简单的窗口。以下代码取自“Visual C++ and MFC Fundamentals”一书,但它不起作用。我收到错误 C2664:BOOL CFrameWnd::Create(LPCTSTR,LPCTSTR, ... ) 无法将参数 2 从 const char[20] 转换为 LPCTSTR。如何更改代码以使其正常工作?

#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;

【问题讨论】:

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

标签: c++ visual-c++ mfc c2664


【解决方案1】:

您可能正在使用 Unicode 字符集(这是默认设置)构建您的应用程序。将违规行更改为:

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

根据字符集,_T 要么扩展为空 (MBSC),要么扩展为 L (Unicode),从而生成 wide character string

【讨论】:

    【解决方案2】:

    如果字符集对你来说并不重要,并且想“永远”摆脱这种错误,你可以去Project Properties -> Configuration Properties -> General -> Character Set,并将其设置为Use Multi-Byte Character Set。如果不是,_T() 和/或 L 是您的朋友(取决于您的字符集设置)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-19
      • 2014-10-04
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      相关资源
      最近更新 更多