Visual Studio 2012 AfxMessageBox()使用注意

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SarahZhang0104/article/details/51346866

在使用VS2012时,突然发现总是提示我AfxMessageBox()重载错误,在网上查查,终于有了答案。

如:

AfxMessageBox(“test”);

只能写成AfxMessageBox(_T(“test”));才能使用,否则编译器会告诉你有两个AfxMessageBox函数,但编译器不知道使用哪一个。
错误提示:

c:\users\sarah\documents\visual studio 2012\projects\mfcapplication1\mfcapplication1\mfcapplication1dlg.cpp(177): error C2665: “AfxMessageBox”: 2 个重载中没有一个可以转换所有参数类型
c:\program files (x86)\microsoft visual studio
11.0\vc\atlmfc\include\afxwin.h(6702): 可能是“int AfxMessageBox(LPCTSTR,UINT,UINT)”
c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(6704): 或 “int AfxMessageBox(UINT,UINT,UINT)”

原因:因VS2012使用了宽字符,所以在前面加_T或L都行
MessageBox(_T"abcd");
or
MessageBox(L"abcd");
如果MessageBox用不了可以考虑用MessageBoxA。

猜你喜欢

转载自blog.csdn.net/SarahZhang0104/article/details/51346866