Question about messagebox function  
Author Message
Bardia Hamedani





PostPosted: Visual C++ Language, Question about messagebox function Top

Hello

I use Visual Studio 2005,I created an MFC Application,then I added a button and I want that when i click on the button a dialog box with a text appear,these are codes,

whats wrong with them

void CHelloDlg::OnBnClickedHello()

{

// TODO: Add your control notification handler code here

//Say Hello to the user

MessageBox("Hello. This is my first Visual C++ Application!");

}

and this is the error:

error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char [48]' to 'LPCTSTR'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Please Help,pleaseeeee



Visual C++13  
 
 
Alex Farber





PostPosted: Visual C++ Language, Question about messagebox function Top

MessageBox(_T("Hello. This is my first Visual C++ Application!"));

or:

MessageBox(L"Hello. This is my first Visual C++ Application!");

VS2005 creates Unicode application by default.


 
 
Viorel.





PostPosted: Visual C++ Language, Question about messagebox function Top

This error message usually appears in case of Unicode applications.

You can put a L before your string: L"Hello...", but the better solution is to use _T macro:

MessageBox(_T("Hello. This is my first Visual C++ Application!"));

Now your program can be compiled in both Unicode and ANSI modes. You have to use such macro for almost all of your strings.

The current mode can be selected in Project Properties --> General --> Character Set.