I am relatively new to C++ and am currently taking a course for it. One of my assignments is to make a calculator for hourly wages and figure gross and net pay based on a fixed percentage for taxes.

I am able to compile the code if I change the default character set from unicode to not used, but my professor is saying I have bad code. While it does compile with unicode turned off, I still get runtime errors that can be ignored during program execution. Also, if I use the same code in dev-C++ I do not have any issues.

I am using Visual Studio 2008 and have gone over the syntax with my book for hours and hours with the same results. I am getting errors while converting from const to char[x] to LPCWSTR. Any help, or even an explanation of the errors would be greatly appreciated!

LINE 2 error C2440: '=' : cannot convert from 'const char [9]' to 'LPCWSTR'

WNDCLASS wc;
	wc.lpszClassName = "PayClass";

LINE 12 error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR'

hWnd = CreateWindow(
		"PayClass",
		"Pay",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		230,
		190,
		NULL,
		NULL,
		hInstance,
		NULL);

Recommended Answers

All 2 Replies

You need to turn off UNICODE. Go to menu Project --> Properties (last item in the menu), Configuration Properties --> General. Then change "Character Set" (3d from bottom on the right) to "Not Set".

Either that or use UNICODE string literals, such as _TEXT("Some string literal")

Use the _T macro, which will automatically convert literal strings to the appropriate type (Unicode or MBCS), based on the build type.

In short, a good thing to do: Always enclose literal strings in the program within the _T macro.

For example:

SomeAPICall(_T("Some literal string"));

See Unicode Programming Summary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.