Can anyone help me to correct this code:
char szBuff[64];
sprintf(szBuff, "%p", m_hWnd);
MessageBox(NULL, szBuff, L"Test print handler", MB_OK);
The error is, it cant convert the 2nd parameter to LPCWSTR.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For this specific case, the fix is quite simple:
That is, use Unicode strings throughout. In general, when programming on Windows, using
wchar_tand UTF-16 is probably the simplest. It depends on how much interaction with other systems you have to do, of course.For the general case, if you’ve got an ASCII (or
char *) string, use either WideCharToMultiByte for the general case, ormbstowcsas @Matthew points out for simpler cases (mbstowcsworks if the string is in the current C locale).