Error C2664 Cwnd Messageboxw
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow cannot convert from const char to lpctstr the company Business Learn more about hiring developers or posting ads with us Stack
Cannot Convert From 'const Char [14]' To 'lpcwstr'
Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of cannot convert parameter 1 from 'const char *' to 'lpcwstr' 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Cannot convert parameter from 'const char[20]' to 'LPCWSTR' up vote 2 down vote favorite 1 When compiling this
Const Char To Lpcwstr
code: #include
Cannot Convert From Char* To Lpcwstr
= "myWindowClass"; // Step 4: the
Const Char Is Incompatible With Lpcwstr
Window Procedure LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, cannot convert from const char to char LPARAM lParam) { switch(msg) { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return http://stackoverflow.com/questions/5481378/cannot-convert-parameter-from-const-char20-to-lpcwstr DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; //Step 1: Registering the Window Class wc.cbSize http://www.cplusplus.com/forum/windows/2359/ = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBoxA(NULL, "Window Registration Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK); return 0; } // Step 2: Creating the Window hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "The title of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBoxA(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow
MessageBox("Hello. This is my first visual C++ Application!"); } and when i build http://www.cplusplus.com/forum/windows/45228/ the program i get this error: Error 1 error C2664: http://m.blog.csdn.net/article/details?id=47083265 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char [48]' to 'LPCTSTR' c:\documents and settings\kokolade\desktop\my_test\test\test\testdlg.cpp 160 1 test i will be glad if someone can point me in the right direction thanks Jun 21, 2011 at 3:28pm UTC methodos (60) You const char should add the letter 'L' before anything between quotation marks. That converts the constant string to LPCTSTR (Long Pointer to Constant T (meaning char* or wchar_t* depending on whether UNICODE is defined) STRing): MessageBox(L"Hello. This is my first visual C++ Application!"); See: http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/1b994ff3-da28-46a8-90ef-6c7fab8dcd21/ Last edited on Jun 21, 2011 at 3:35pm UTC cannot convert from Jun 21, 2011 at 4:42pm UTC webJose (2948) Sorry, but wrong. In Disch's words: There are 3 message box functions: MessageBoxA, MessageBoxW, and MessageBox, and they all take 3 different types of string datatypes. -MessageBox: Takes LPCTSTR, which is a pointer to const TCHAR. -MessageBoxA: Takes LPCSTR, which is a pointer to const char. -MessageBoxW: Takes LPCWSTR, which is a pointer to const wchar_t. Therefore, saying "Use MessageBox() with a const wide char string" is just wrong. You can do either of the following: 1
2
3
MessageBox(TEXT("Hello"), ...); MessageBoxA("Hello", ...); MessageBoxW(L"Hello", ...); Any other combination is just wrong in Disch's eyes. In mine kind of. I would accept MessageBox(L"Hello", ...); if surrounded by #ifdef _UNICODE ... #endif . Topic archived. No new replies allowed. C++ Information Tutorials Reference Articles Forum Forum BeginnersWindows ProgrammingUNIX/Linux ProgrammingGeneral C++ ProgrammingLoungeJobs Home page | Privacy policy© cplusplus.com, 2000-2016 - All rights reserved - v3.1Spotted an error? contact us
C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'char *' to 'LPCTSTR' 后来发现解决方法很简单,点击“项目”-》“属性”-》“配置属性”-》“常规”-》“字符集”选择“使用多字节字符集” 问题解决,后来发现很多问题都能通过这个办法解决,如: error C2440: '=' : cannot convert from 'const char [13]' to 'LPCWSTR'。 等问题都能用该方法解决。 vs 2010英文版下: Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set". 上一篇 下一篇 暂无评论,我去发表~ 评论(0) c语言,color,微软,visual studio 2005,class,mfc 我的热门文章 用VC++6.0上位机程序控制步进电机 基于Opencv的车辆识别系统研究 OpenCV 透视变换【图像归一化矫正】 更改Visual Studio 2010的主题设置[.vssettings格式] 学习java书籍 相关博文 未登录 •首页 •移动开发 •Web前端 •架构设计 •编程语言 •互联网 •数据库 •系统运维 •云计算 •研发管理 •综合 0 0 0 分享 微信分享新浪微博QQ好友QQ空间 取 消