读书人

照着书上做,出错了,该如何解决

发布时间: 2012-03-19 22:03:04 作者: rapoo

照着书上做,出错了

C/C++ code
void CDemo12Dlg::OnBnClickedButtonText(){    // TODO: 在此添加控件通知处理程序代码    CDemo12App* pApp=(CDemo12App*)AfxGetApp();    CWnd* pWnd=pApp->m_pMainWnd;    CString strText=_T("");    strText.Format("pMainWnd=0X%x\nthis=0X%x",pWnd,this);//这一行出错了    AfxMessageBox(strText);}1>------ 已启动生成: 项目: Demo1.2, 配置: Debug Win32 ------    1>生成启动时间为 2012/2/15 10:37:19。    1>InitializeBuildStatus:1>  正在对“Debug\Demo1.2.unsuccessfulbuild”执行 Touch 任务。    1>ClCompile:1>  所有输出均为最新。    1>  Demo1.2Dlg.cpp    1>d:\visual studio\project\demo1.2\demo1.2\demo1.2dlg.cpp(163): error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [24]”转换为“const wchar_t *”    1>          with    1>          [        1>              BaseType=wchar_t,            1>              StringTraits=StrTraitMFC_DLL<wchar_t>            1>          ]1>          与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换    1>    1>生成失败。    1>    1>已用时间 00:00:00.25    ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========


[解决办法]
unicode吧,strText.Format(_T("pMainWnd=0X%x\nthis=0X%x"),pWnd,this);
[解决办法]
或者把Unicode选项关掉

读书人网 >VC/MFC

热点推荐