Jump to content
  • Advertisement
Sign in to follow this  
Stovek

A Common Windows Programming Issue?

This topic is 4027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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")

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!