cannoct convert from const wchar_t[12] to LPCSTR

I am getting this error and I don't know what's wrong, here's the code sample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <Windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR nCmdLine, int nCmdShow)
{
	const wchar_t CLASS_NAME[] = L"WindowsClass";
	WNDCLASS wc = { NULL };
	wc.lpfnWndProc = WindowProc;
	wc.lpszClassName = CLASS_NAME;
	wc.hInstance = hInstance;
	RegisterClass(&wc);

}
Add UNICODE and _UNICODE macros to preprocessor definitions. Alternatively, use WNDCLASSW and RegisterClassW directly.
Last edited on
Although modoran is correct, I want to add that it is helpful to know how to convert between these types:

- C-String to Wide: http://msdn.microsoft.com/en-us/library/eyktyxsx.aspx

- Wide To C-String: http://msdn.microsoft.com/en-us/library/s7wzt4be.aspx

But again, calling the wide versions of these functions is the correct answer. If you are unsure if a wide version exists and the documentation does not come through then I suggest DLL Export Viewer by Nirsoft: http://www.nirsoft.net/utils/dll_export_viewer.html
If you're using Visual Studio, you should set the Character Set property of your project to Unicode rather than add UNICODE and _UNICODE to the project's preprocessor settings.

As you're using wWinMain and wchar_t, mordoran's second suggestion is prob. better; to use WNDCLASSW and RegisterClassW.

In fact, you should prob be using the -W versions of the Windows API calls whenever appropriate.

Andy
Last edited on
When working with the Windows API, I would normally use MultiByteToWideChar and WideCharToMultiByte rather than the CRT calls mbstowcs* and wcstombs*

Andy

MultiByteToWideChar function
http://msdn.microsoft.com/en-us/library/dd319072%28v=vs.85%29.aspx

WideCharToMultiByte function
http://msdn.microsoft.com/en-us/library/dd374130%28v=vs.85%29.aspx
Last edited on
Topic archived. No new replies allowed.