menu

Jun 21, 2011 at 2:36pm
please i do need some help with this. I have this function,
void CtestDlg::OnClickedIdhello()
{
// TODO: Add your control notification handler code here
MessageBox("Hello. This is my first visual C++ Application!");

}

and when i build the program i get this error:
Error 1 error C2664: '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
You 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
Jun 21, 2011 at 4:42pm
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.