A Common Windows Programming Issue?

Started by
4 comments, last by Stovek 16 years, 10 months ago
I've been programming in C++ for quite some time now, but I decided to take a step forward, trying out windows and directx. I have skimmed through several books on the subject, but most of them said to "write this down, but don't bother with what it means", which isn't a very good way for me to learn--examples without reasoning, that is. Getting to the point, I checked out Programming Role Playing Games with DirectX - 2nd Edition, and it seems to do a decent job of explaining. Unfortunately, the very first program in the book, a Windows Application Framework, fails to compile. One line with an issue: wcex.lpszClassName = 11; The error reads: "cannot convert from 'int' to 'LPCWSTR'" There are other errors, but they all revolve around the same reasoning ("cannot convert parameter 2 from 'char [11]' to 'LPCWSTR'" in reference to a hInst, NULL parameter line for a CreateWindow function) LPCWSTR doesn't appear anywhere in the code... What is the problem? My compiler is Visual Studios 2005, in case that's needed.
Advertisement
LPCWSTR -- the str at the end would only make me assume its a string variable and not an integer. and I believe its just a random name, that gets displayed on the top bar of the window, or at the program list next to the start menu. probably a typo in the righting, there seems to be quite alot of typos in programming books.

as for the hInst, I believe you have to pass the programs Instance as that what the window uses as a link to the program. The Instance should be a passed in variable of the Winmain function.

hope that helps
-----------------------------------------------The ZoloProject
Go ahead and Google for LPCWSTR. You'll find that it's some kind of Windows wide string type. What it comes down to, is that the variabeles you're passing can't implicitely be converted to this LPCWSTR type. However, many others have had the same problems, so it's not hard to find solutions: Google: LPCWSTR.

I'm sure some of those hits will be helpfull. :)
Create-ivity - a game development blog Mouseover for more information.
LPCWSTR is a Long Pointer to Constant Wide Character String. What most likely is the problem is that your environment is using Unicode. A char [11] is not a wide character string.

You can either:

A) Stop using unicode in the project settings (not recommended)
B) Use wchar_t instead of char, and all the equivalant functions (not recommended)
C) Place an L outside strings to define them as wide, such as L"Hello World"
D) Use TCHAR's. This is probably the most recommended way, because it will work in Unicode or non Unicode. _T("Hello World")
wcex.lpszClassName = 11;

that author must not be a windows programmer he he he. you don't assign an integer to window's classname. change that to:

wcex.lpszClassName = TEXT("11");
or
wcex.lpszClassName = TEXT("MyGameWindow"); // a more meaningful name

and at least that error should be gone.

there other error you are getting "cannot convert parameter 2 from 'char [11]' to 'LPCWSTR'" is the oh so common unicode error (by default VS2005 defaults to unicode, making many older apps that don't use the TEXT macro fail to compile. you can turn off unicode in the compiler settings.

the other error, "NULL parameter line for a CreateWindow function" i'm not sure though. fix the other errors first and then let's see what happens.
That cleared the problem right up :D

Thanks bunches.

This topic is closed to new replies.

Advertisement